WordPress.org

Support

Support » Plugins and Hacks » WooCommerce Sold Out Products » [Resolved] Warning division by zero after woocommerce update

[Resolved] Warning division by zero after woocommerce update

Viewing 9 replies - 1 through 9 (of 9 total)
  • Here are some screenshots of the situation when Sold Out is activated:

    screenshot 1

    screenshot 2

    Hmmm…..I just tried activating the parent Canvas theme and then the issue is gone too.

    Conflict seems to be narrowed down to child theme and active Sold out plugin.

    Line 993 in child themes functions php goes to this piece of code given to me by Gerhard some time ago I recall having the same problem then as well and I think he gave me this code to fix it:

    // Add save percent next to sale item prices.
    
    add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
    
    function woocommerce_custom_sales_price( $price, $product ) {
    
        $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
    
        return $price . sprintf( __(' - %s', 'woocommerce' ), $percentage . '%' );
    
    }
    
    add_filter( 'woocommerce_variable_sale_price_html', 'woocommerce_custom_variable_sales_price', 10, 2 );
    
    function woocommerce_custom_variable_sales_price( $price, $variable ) {
    
        $reg_price  = get_post_meta( $variable->children[0], '_regular_price', true );
    
        $sale_price = get_post_meta( $variable->children[0], '_sale_price', true );
    
        $percentage = round( ( ( $reg_price - $sale_price ) / $reg_price ) * 100 );
    
        return $price . sprintf( __(' - %s', 'woocommerce' ), $percentage . '%' );
    
    }

    This is specific on line 993:

    $percentage = round( ( ( $reg_price – $sale_price ) / $reg_price ) * 100 );

    Hi Annie

    I assume you are running WooCommerce 2.1? The way prices works has changed hence it wont work the way it did in 2.0.

    Can I suggest you log a ticket with WooThemes as this is not related to the extension but custom code in your theme’s functions.php file.

    Oh, hi Gerhard!

    Thx for your respons.
    I was bussy getting that code in here, not noticing you responded!

    This has nothing to do with that code I just posted that you gave me at some point earlier?

    Thx,
    Annie

    Thing is as soon as I deactivate my child theme with this code in it, percentage still shows fine without the error.

    I will remove that code from my child theme first and see if that fixes it.

    Annie

    Hi Annie

    Yes I understand however the code is not related to the extension, and is custom code. This forum is only for issues related to the sold out products extension hence why I suggested you contact WooThemes for support on this.

    Oh wait, that is the code to show the percentage off!
    As soon as I remove that code sold out works fine too.

    I will submit a ticket at Woothemes and ask for Andrew, he helped me with this code.

    Sorry for my monologe haha, maybe it helps some one with same issue 🙂

    Thx Gerhard!
    Annie

    Hi Gerhard,

    I submitted a ticket as you adviced me to and this is Andrews answer:

    Andrew Benbow (WooThemes)

    Mar 13 17:55

    Hi Annie

    I’ve just tested that function and it working correctly , I’m not sure what the sold out plugin is doing but it sounds like it is setting the sale price to 0. You should the developer

    Andrew – WooCommerce Ninja
    WooThemes Support

    Thing is they both ( your plugin and the custom code ) worked fine togheter before the update.

    After the update one of them messes up the other.
    Could Andrew be right that the sold out sets the sale price to 0 now?

    Hope you can help?

    Annie

    Hi Gerhard,

    Any ideas on how to solve this please? Maybe consult with your colleque Andrew?

    I can not update Woocommerce until this is solved or will have to let go of either your plugin or the percentage code and clients does not want to lose either one of these options..

    Could Andrew be right that the sold out sets the sale price to 0 now?

    Please help?

    Annie

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Warning division by zero after woocommerce update’ is closed to new replies.
Skip to toolbar