Home / Woo-Commerce / Display Product Discount/Offer percentage in bubble WooCommerce

Display Product Discount/Offer percentage in bubble WooCommerce

Display Product Discount/Offer percentage in bubble WooCommerce.

So what I have here is a code snippet to calculate individual product discount and display it in sale bubble. Replace all the codes in following files your theme folder/woocommerce/loop/sale-flash.php and  your theme folder/woocommerce/single-product/sale-flash.php with below code.

<?php
/**
* Product loop sale flash
*
* @author Vivek R @ WPSTuffs.com
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly
global $post, $product;
?>
<?php if ($product->is_on_sale() && $product->product_type == ‘variable’) : ?>
<div class=”bubble”>
<div class=”inside”>
<div class=”inside-text”>
<?php
$available_variations = $product->get_available_variations();
$maximumper = 0;
for ($i = 0; $i < count($available_variations); ++$i) {
$variation_id=$available_variations[$i][‘variation_id’];
$variable_product1= new WC_Product_Variation( $variation_id );
$regular_price = $variable_product1 ->regular_price;
$sales_price = $variable_product1 ->sale_price;
$percentage= round((( ( $regular_price $sales_price ) / $regular_price ) * 100),1) ;
if ($percentage > $maximumper) {
$maximumper = $percentage;
}
}
echo $price . sprintf( __(‘%s’, ‘woocommerce’ ), $maximumper . ‘%’ ); ?></div>
</div>
</div><!– end callout –>
<?php elseif($product->is_on_sale() && $product->product_type == ‘simple’) : ?>
<div class=”bubble”>
<div class=”inside”>
<div class=”inside-text”>
<?php
$percentage = round( ( ( $product->regular_price $product->sale_price ) / $product->regular_price ) * 100);
echo $price . sprintf( __(‘%s’, ‘woocommerce’ ), $percentage . ‘%’ ); ?></div>
</div>
</div><!– end bubble –>
<?php endif; ?>

About Sushil_kumar

Check Also

aws

how to setting WordPress on Amazon EC2

Step 1: Create an AWS Account Step 2: Create an Instance To create a new …

Leave a Reply

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

0

December 9, 2016

Clear all