Anas
Anas

Reputation: 65

Calculate price and display on WooCommerce product single page under price (simple price, variable price)

I am planing to show a new price on my WooCommerce product page for all products. This is the installment price per month. I need to show this below the normal price (variable price and simple price) something like this.

0% interest installments starting from Rs.3,093

where Rs.3,093 is the new price.

This is the calculation I tried on W3 schools, and I got the calculation correct.

whereas 60000 is the price of the product
multiplied by this number 5.15464
divided by 100

Answer is 3,093
(answer should be rounded off to the nearest integer)

I need a custom function for this that I can add to my functions.php

<script>
var x = myFunction(60000, 5.15464, 100);
function myFunction(a, b, c) {
  return Math.round (a * b / c);
}
</script>

Upvotes: 2

Views: 2330

Answers (1)

Praveen
Praveen

Reputation: 1005

This code will display the value or content before Add to Cart button in woocommerce product page.

        add_action( 'woocommerce_single_product_summary', 'show_emi', 20 );
      function show_emi() {
       global $product; 
       $id = $product->get_id();
        $product = wc_get_product( $id );
        $a=$product->get_price();
        $b  = 5.15464;
        $c = 100;
        $d = $a * $b;
        $total = $d/$c;
          echo $total;
      }

Upvotes: 1

Related Questions