Reputation:
I am attempting to grab the sale price of a woocommerce product and than display the price 20% off.
The code I have right now is sort of working. Its grabbing the "regular" price and displaying that as 20% off. But I would like it to grab the sale price.
How is this done in woocommerce?
Here is my PHP
<?php
if($product->product_type=='variable') {
global $product;
$sales_price = esc_attr( $product->get_display_price() );
$discount = 20;
$currency = esc_attr( get_woocommerce_currency() );
$new_price = ($sales_price * $discount) / 20;
echo 'Get this product for '.$new_price.$currency.' with (Promo code)';
}
?>
Upvotes: 1
Views: 2712
Reputation: 136
You need to get sale price something like this $_product->get_sale_price();
instead of esc_attr( $product->get_display_price()
Upvotes: 1