Home Forums WoodMart support forum Product style promotional price is not displayed Reply To: Product style promotional price is not displayed

#529188

Hello,

Please add the below code to functions.php in the Child theme

// For simple products.
add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
    /*global $product;
    // Show regular and sale price for specified product IDs
    if ( in_array( $product->get_id(), array( 1, 2, 3, 28 ) ) ) {
        return $price;
    }
    // Show regular and sale price if product is in any of the specified categories.
    if ( has_term( array( 'hoodies', 'accessories', 'tshirts' ), 'product_cat', $product->get_id() ) ) {
        return $price;
    }*/
	
	return wc_price( $sale_price );
}

// For variable products.
add_filter( 'woocommerce_variable_price_html', 'dcwd_variable_price', 10, 2 );
function dcwd_variable_price( $price_html, $product ) {
	if ( $product->is_on_sale() ) {
        /*// Show regular and sale price for specified product IDs
        if ( in_array( $product->get_id(), array( 1, 2, 3, 7932 ) ) ) {
            return $price_html;
        }
        // Show regular and sale price if product is in any of the specified categories.
        if ( has_term( array( 'hoodies', 'accessories', 'tshirts' ), 'product_cat', $product->get_id() ) ) {
            return $price_html;
        }*/

		$prices = $product->get_variation_prices( true ); 
		$min_price = current( $prices['price'] );
		$price = wc_price( $min_price ); 
		return 'From: ' . $price;
	}
	return $price_html;
}

Best Regards.