ProductWoocommerce

Show discount text information in single product page

    
// Display custom information above the Add to Cart button when there is a discount add_action('woocommerce_before_add_to_cart_quantity', 'display_discount_information', 10); function display_discount_information() { global $product; // Check if the product has a sale price if ($product->is_on_sale()) { $regular_price = wc_price($product->get_regular_price()); $sale_price = wc_price($product->get_sale_price()); $amount_saved = $product->get_regular_price() - $product->get_sale_price(); $amount_saved_price = wc_price($amount_saved); $discount_percentage = round(($amount_saved / $product->get_regular_price()) * 100); echo '<div class="discount-information">'; echo '<p>' . sprintf(__('From <del> %s </del> <br>You Save: %s (%s)', 'discount-text'), $regular_price, $amount_saved_price, $discount_percentage . '%') . '</p>'; echo '</div>'; } }

3 thoughts on “Show discount text information in single product page”

Leave a Reply

Your email address will not be published. Required fields are marked *