I need to develop a script in function file that display sale price for specific categories for registered users. This code work fine.
I need to add sale price design to it
function thenga_customer_specific_pricing( $price, $product ) {
if ( ! is_user_logged_in() ) {
return $price;
}
$id = $product->get_id();
if( has_term( 'daniel-wellington', 'product_cat' ,$id ) ){
// Give these customers a 20% discount.
return $price * 0.8;
} elseif( has_term( 'giardino-segreto', 'product_cat' ,$id ) ){
return $price * 0.85;
} else {
return $price;
}
}
add_filter( 'woocommerce_product_get_price', 'thenga_customer_specific_pricing', 10, 2 );
I expect an output like this:
Was: 100€ Now: 80€
I tried this filter :
function custom_dynamic_sale_price_html( $price_html, $product ) {
if( $product->is_type('variable') ) return $price_html;
$price_html = wc_format_sale_price( wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ), wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) ) ) . $product->get_price_suffix();
return $price_html;
}
add_filter( 'woocommerce_get_price_html', 'custom_dynamic_sale_price_html', 20, 2 );
but It work in all products, how I can call this filter only in specific categories?