wc_get_price_decimals │ filter-hook │ WC 2.3

Allows you to change the number of decimal places in prices.

The number of decimal places can also be changed in the admin area:
WooCommerce->Settings->General->Currency options

Usage

add_filter( 'wc_get_price_decimals', 'wp_kama_wc_get_price_decimals_filter' );

/**
 * Function for `wc_get_price_decimals` filter-hook.
 * 
 * @param  $option 
 *
 * @return 
 */
function wp_kama_wc_get_price_decimals_filter( $option ){
	// filter...
	return $option;
}
$option
The number of decimal places.

Examples

#1 Remove decimal places

add_filter( 'wc_get_price_decimals', '__return_zero' );

echo wc_price( 150.201 ); //> 150

// This is the same as
add_filter( 'wc_get_price_decimals', 'change_price_decimals' );

function change_price_decimals(){
	return 0;
}

echo wc_price( 150.201 ); //> 150

#2 Change the number of decimal places

add_filter( 'wc_get_price_decimals', 'change_price_decimals' );

function change_price_decimals(){
	return 1;
}

echo wc_price( 150.201 ); //> 150.2

Changelog

Since 2.3 Introduced.

Where the hook is called

wc_get_price_decimals()
wc_get_price_decimals
woocommerce/includes/wc-formatting-functions.php 568
return absint( apply_filters( 'wc_get_price_decimals', get_option( 'woocommerce_price_num_decimals', 2 ) ) );

Where the hook is used in WooCommerce

Usage not found.