Added 2 functions, how do I make 2nd one target the 1st one?
-
Hi!
I have this code to add a shortcode to display Product price:
function so_30165014_price_shortcode_callback( $atts ) { $atts = shortcode_atts( array( 'id' => null, ), $atts, 'bartag' ); $html = ''; if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){ $_product = wc_get_product( $atts['id'] ); $number = number_format($_product->get_price(), 2, ',', '.'); $html = $number . " €"; }
And this code to hide the decimal number in product price if they would be 0:
add_filter('woocommerce_price_trim_zeros', 'wc_hide_trailing_zeros', 10, 1); function wc_hide_trailing_zeros( $trim ) { return true; }
Now, the product price that WooCommerce shows is correct. However on the single product page, which I made custom, the price still displays the decimals (for example: 2.460,00 €).
How would I make the second code take effect on the first one?
Thank you!
- This topic was modified 3 years, 4 months ago by . Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Added 2 functions, how do I make 2nd one target the 1st one?’ is closed to new replies.