WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce Sold Out Products
[resolved] Warning division by zero after woocommerce update (10 posts)

  1. LogoLogics
    Member
    Posted 4 months ago #

    Hello,

    Since I did the most recent update of Woocommerce, some products show:
    "Warning: Division by zero in /home/namedomain/public_html/Anshop/wp-content/themes/canvas-child-01/functions.php on line 993"

    http://www.logologics.nl/Anshop/product/snob-broekje-grijs-voile/

    After deactivating every plugin and activating them one by one, the sold old plugin seems to be the cause of this.

    As soon as I deactivate the sold out everything goes back to normal.

    Is there a way to fix this, I really would like to be able to keep this awesome plugin?

    Thx,
    Annie

    https://wordpress.org/plugins/woocommerce-sold-out-products/

  2. LogoLogics
    Member
    Posted 4 months ago #

    Here are some screenshots of the situation when Sold Out is activated:

    screenshot 1

    screenshot 2

  3. LogoLogics
    Member
    Posted 4 months ago #

    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 );

  4. Gerhard
    Member
    Plugin Author

    Posted 4 months ago #

    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.

  5. LogoLogics
    Member
    Posted 4 months ago #

    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

  6. LogoLogics
    Member
    Posted 4 months ago #

    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

  7. Gerhard
    Member
    Plugin Author

    Posted 4 months ago #

    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.

  8. LogoLogics
    Member
    Posted 4 months ago #

    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

  9. LogoLogics
    Member
    Posted 4 months ago #

    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

  10. LogoLogics
    Member
    Posted 4 months ago #

    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

Reply

You must log in to post.

About this Plugin

About this Topic