- This topic has 2 replies, 2 voices, and was last updated 4 years, 5 months ago by
Frederik Leemans.
-
AuthorPosts
-
April 10, 2020 at 2:42 pm #10142
Frederik Leemans
ParticipantDear Support,
I’m using Woo Discount Rules to manage discounts, but unfortunately it doesn’t play nice with the Azuma Pro Sale Banner.
I have a snippet to calculate the discount % based on the discount rules, but could you provide a snippet to inject that % correctly into the Sale Banner?
Thanks,
Frederik
<div id=”ConnectiveDocSignExtentionInstalled” data-extension-version=”1.0.4″></div>
<div id=”ConnectiveDocSignExtentionInstalled” data-extension-version=”1.0.4″></div>April 10, 2020 at 3:48 pm #10146Andy
KeymasterHi Frederik,
These are the two functions that output the standard sale price % discount;
To change either of these functions, you will need to copy the code – making any changes to use your custom discount rules – into the functions.php file of a child theme.
This
azuma_before_loop_sale_flash
function just adds the start of the theme’s div wrapper, so no need to modify this if you don’t need to change it:function azuma_before_loop_sale_flash() { global $product; if ( $product->is_on_sale() ) { echo '<div class="sale-flash">'; } }
This
azuma_after_loop_sale_flash
function calculates the discount % and outputs it, so you would need to remove the code that calculates the discount and replace with your own code:function azuma_after_loop_sale_flash() { global $product; if ( $product->is_on_sale() ) { if ( ! $product->is_type( 'variable' ) && $product->get_regular_price() && $product->get_sale_price() ) { $discount_price = $product->get_regular_price() - $product->get_sale_price(); if ( $discount_price > 0 ) { $max_percentage = ( $discount_price / $product->get_regular_price() ) * 100; } else { $max_percentage = 0; } } else { $max_percentage = 0; foreach ( $product->get_children() as $child_id ) { $variation = wc_get_product( $child_id ); $price = $variation->get_regular_price(); $sale = $variation->get_sale_price(); $percentage = ''; if ( $price != 0 && ! empty( $sale ) ) { $percentage = ( $price - $sale ) / $price * 100; } if ( $percentage > $max_percentage ) { $max_percentage = $percentage; } } } echo '<br /><span class="sale-percentage">-' . esc_attr( round($max_percentage) ) . '%</span>'; echo '</div>'; } }
for example:
function azuma_after_loop_sale_flash() { global $product; if ( $product->is_on_sale() ) { /* YOUR CUSTOM CODE TO CALCULATE YOUR DISCOUNT */ echo '<br /><span class="sale-percentage">-' . esc_attr( $your_calculated_discount ) . '%</span>'; echo '</div>'; } }
April 10, 2020 at 7:27 pm #10149Frederik Leemans
ParticipantGreat, that addresses my problem.
Thanks!
<div id=”ConnectiveDocSignExtentionInstalled” data-extension-version=”1.0.4″></div>
<div id=”ConnectiveDocSignExtentionInstalled” data-extension-version=”1.0.4″></div> -
AuthorPosts
- The topic ‘Sale banner integration with Woo Discount Rules’ is closed to new replies.