Home Forums Azuma Pro Sale banner integration with Woo Discount Rules

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10142
    Frederik Leemans
    Participant

    Dear 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>

    #10146
    Andy
    Keymaster

    Hi 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>';
        }
    }
    #10149
    Frederik Leemans
    Participant

    Great, 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>

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Sale banner integration with Woo Discount Rules’ is closed to new replies.