V
V
Valentina2021-01-15 18:00:04
WooCommerce
Valentina, 2021-01-15 18:00:04

How to remove duplicate price when Woocommerce condition is met?

I display a new price when a number of conditions are met, but I display it next to the old price. How to remove the old price exactly display:none

Here is my code that displays the new price:

add_filter( 'woocommerce_get_price_html', 'custom_product_price_display', 10, 2 );
add_filter( 'woocommerce_cart_item_price', 'custom_product_price_display', 10, 2 );
function custom_product_price_display( $price, $product ) {
      global $post, $woocommerce, $product;
       // Price per meter prefixed
      $active = get_post_meta($post->ID,"_calculatorscript_active",true);		
    // if the calculator exists, enable the form
    if($active != 'no' && $active != NULL) {
    $calculatorValue = get_post_meta($post->ID,"_calculatorscript_value",true);
        $unit_price_html = wc_price( $product->get_price() / $calculatorValue );
        $price .= ' <span class="amount" style="display: initial;" >' . $unit_price_html . '/м<sup>2</sup></span>';
    } 
    // Prefix" per unit"
    else {
        $price .= ' ';
    }
    return $price;
}


Here's what ends up happening:

6001ae258e5ad572938550.png 6001ae2cac9f1223306168.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question