Untitled
unknown
plain_text
10 months ago
1.4 kB
6
Indexable
add_filter( 'woocommerce_get_price_html', 'modify_price', 1000000000, 2);
add_filter( 'woocommerce_variation_get_price_html', 'modify_price', 1000000000, 2);
function modify_price($price_html, $product){
if (!is_user_logged_in()){
if( $product->is_type( 'simple' ) || $product->is_type( 'variation' ) ){
$regular_price = get_post_meta($product->get_id(), '_regular_price', true);
$sale_price = get_post_meta($product->get_id(), '_sale_price', true);
if (!empty($sale_price)){
$price = $sale_price;
} else {
$price = $regular_price;
}
$price_inc_tax = $price * 120/100;
$price_html = wc_price($price).' HT<br>'.wc_price($price_inc_tax).' TTC';
}
if( $product->is_type( 'variable' ) ){
$min_price = $product->get_variation_price( 'min' );
$max_price = $product->get_variation_price( 'max' );
if ($min_price === $max_price){
$price = $min_price;
$price_inc_tax = $price * 120/100;
$price_html = wc_price($price).' HT<br>'.wc_price($price_inc_tax).' TTC';
} else {
$ex_tax_range = wc_format_price_range( $min_price, $max_price );
$price_inc_tax_min = $min_price * 120/100;
$price_inc_tax_max = $max_price * 120/100;
$inc_tax_range = wc_format_price_range( $price_inc_tax_min, $price_inc_tax_max );
$price_html = $ex_tax_range.' HT<br>'.$inc_tax_range.' TTC';
}
}
}
return $price_html;
}Editor is loading...
Leave a Comment