We have loads of products on our woo commerce and are trying to automate a few things.
All our products are 20% off if you use our specific promo code.
So at the top of every product page there is a sentence that says "Get this product for (price -20%) with (Promo code)
I would like to create a function that gets the product's price and subtracts 20% off it. Displaying in a sentence where we can update the promo code by updating one function.
Any ideas on the best way to achieve this? I dont wana use any plugins.
Thanks for any help!
We have loads of products on our woo commerce and are trying to automate a few things.
All our products are 20% off if you use our specific promo code.
So at the top of every product page there is a sentence that says "Get this product for (price -20%) with (Promo code)
I would like to create a function that gets the product's price and subtracts 20% off it. Displaying in a sentence where we can update the promo code by updating one function.
Any ideas on the best way to achieve this? I dont wana use any plugins.
Thanks for any help!
Assuming you would put this in a woocommerce template file, wherever you want it to display:
<?php
global $product;
$regular_price = esc_attr( $product->get_display_price() );
$discount = 20;
$currency = esc_attr( get_woocommerce_currency() );
$new_price = ($regular_price * $discount) / 100;
echo 'Get this product for '.$new_price.$currency.' with (Promo code)';
?>
Untested, but should do the trick.
Depending on what you take the percent from (before tax, after tax, etc) and
you'll want this code:
<?php
$reg_price = esc_attr( $product->get_display_price() );
$sale_price = .8 * $reg_price;
$echo 'On Sale now for ' . $sale_price . ' with promo code!';
?>
put it in your product single page where you want it to go