How do I call the price in functions file
-
Hi,
Currently I use the following code in my theme functions.php file to add “Save xx%” on sale products, however with this plugin enabled this text no longer displays therefore I have deactivated the plugin for now.
Could you please advise how I would get it to show with your plugin activated and what I would need to edit in the following code.
// Show percentage discount next to price add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 ); function custom_price_format( $price, $product ) { // Main Price $regular_price = $product->is_type('variable') ? $product->get_variation_regular_price( 'min', true ) : $product->get_regular_price(); $sale_price = $product->is_type('variable') ? $product->get_variation_sale_price( 'min', true ) : $product->get_sale_price(); if ( $regular_price !== $sale_price && $product->is_on_sale()) { // Percentage calculation and text $percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%'; $percentage_txt = __(' <font color="#b22222">Save', 'woocommerce' ).' '.$percentage; $price = '<del>' . wc_price($regular_price) . '</del> <ins>' . wc_price($sale_price) . '</ins> <span><br>' . $percentage_txt . '</span></font>'; } return $price; }
- The topic ‘How do I call the price in functions file’ is closed to new replies.