V
V
Valentina2021-01-14 17:22:45
WooCommerce
Valentina, 2021-01-14 17:22:45

What is wrong with my code and How to show new price for Woocommerce item?

I want to show the new price of an item. I wrote a code where there are conditions, and if they are true, they will return an arbitrary php template.
Here is the code:

function laminate_get_price($price, $product) {
   global $post, $woocommerce, $product;	
  
       $active = get_post_meta($post->ID,"_calculatorscript_active",true);
  
    if($active != 'no' && $active != NULL) {
    $calculatorValue = get_post_meta($post->ID,"_calculatorscript_value",true);
      require_once 'new-price.php';
    }
return false;
    }
  
   add_action('woocommerce_get_price', 'laminate_get_price', $product, 2);


Template code:

<p class="price">
  <span class="woocommerce-Price-amount amount"><?php echo number_format((get_post_meta($post->ID,"_regular_price",true) / $calculatorValue),2,",",""); ?> <?php echo get_woocommerce_currency_symbol("UAH"); ?> </span></p>


On the page I see the new price, but up to the content of the product and with some problems. What's wrong with the code?
If I use woocommerce_get_price_htmlthen all prices disappear except for the one on the product that meets the conditions.

Image of my page
600053b0346df878314023.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