Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the style of variable products price woocommerce

The following code works correctly for single products, but I want to use this code for multiple variations of several kinds of products.

Actually, this code is adding the sale price with the original price before the sale price starts.

I am working on scheduling sales and I want to show both the sale price and the original, pre-sale price so that customers can see how much the discount will save them.

function cw_change_product_price_display( $price_html ) {
    global $product;
    global  $woocommerce;
    if ( $product->is_on_sale() ) {
        return $price_html;
    } elseif($product->get_sale_price()){
        $price =wc_price($product->get_sale_price());
        return $price_html . $price;
    } else {
        return $price_html;
    }
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
like image 834
Raja Fahad Bin Asif Avatar asked Nov 07 '22 18:11

Raja Fahad Bin Asif


1 Answers

I think your question is not clear but it seems that you should use the following hook to change the variable price of WooCommerce.

add_filter('woocommerce_product_variation_get_price', 'cw_change_product_price_display', 99, 2);
like image 200
Morteza Barati Avatar answered Dec 08 '22 01:12

Morteza Barati