Home > Back-end >  Woocommerce product detail page remove price decimals
Woocommerce product detail page remove price decimals

Time:10-14

I'm customizing Woocommerce plugin, trying to remove decimals from product variation prices in product detail page.

Ex- if someone select option i want to display the regular and sales prices without decimals and the other locations of site like shop, cart, checkout no need to change.

I found this filter but it change prices of whole site.

add_filter( 'woocommerce_price_trim_zeros', '__return_true' ); 

https://snipboard.io/GXgtUi.jpg

anyone have idea or solution about archive this, Thanks a lot

CodePudding user response:

You can try below code snippet into your theme function.php file

add_filter( 'formatted_woocommerce_price', 'ums_remove_zero_decimals', 10, 5 );
function ums_remove_zero_decimals( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
$product_id = get_the_ID();
$product = wc_get_product( $product_id );

if( is_single()) {
    if($product->is_type( 'variable' )) {
        return (int) round( $price );
    }
    else {
        return ( $formatted_price);
    }
}
}

Let me know if this works for you or not.

CodePudding user response:

You can edit the format of the product price , woocommerce > settings > general > scroll down , currency options , number of decimals : 0

  • Related