• Since one of the last updates we see Server-Errors when Customers order our “free” subscription. (Woocommerce Product with a price of 0). This leads to an order cancellation. After some debugging I found the error in the following class:

    /plugins/yith-woocommerce-subscription/includes/class.ywsbs-subscription-order.php
    -> LINE 180 : $new_cart->cart_contents[ $new_cart_item_key ][‘data’]->set_price( $current_price );

    calling the function “setPrice” leads to a NULLREFERENCE-Exception when the price is 0. My Quickfix was:
    if( $current_price > 0 ) {
    $new_cart->cart_contents[ $new_cart_item_key ][‘data’]->set_price( $current_price );
    }

    • This topic was modified 10 months, 3 weeks ago by ngoels.
    • This topic was modified 10 months, 3 weeks ago by ngoels.
    • This topic was modified 10 months, 3 weeks ago by ngoels.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Alberto Ruggiero

    (@witcher83)

    Hello @ngoels,

    the price cannot be 0 because PayPal won’t allow it.

    Thread Starter ngoels

    (@ngoels)

    Yes, but a “0” price won’t trigger payment. So how do you build “free” subscriptions what’s your suggestion?

    Plugin Support Alberto Ruggiero

    (@witcher83)

    Hello @ngoels,

    this is not possible with the plugin. When trying to pay the plugin will always try to connect with PayPal and you will get the error.

    Thread Starter ngoels

    (@ngoels)

    Hello Alberto,

    sry – but this is not correct. Please see:

    -> The option to disable payment (which makes no sense when the Price is 0) works as follows:

    add_filter( 'woocommerce_cart_needs_payment', 'filter_cart_needs_payment_callback', 100, 2 );
    function filter_cart_needs_payment_callback( $needs_payment, $cart ) {
    return $cart->subtotal > 0 ? $needs_payment : false;
    }

    -> so there is never a connection to paypal or any other payment provider in the checkout, when the Price is 0.

    Unfortunately the YITH-Subscriptions Plugin crashes because the value of the $currentprice variable is not validated. (please see my first post):
    /plugins/yith-woocommerce-subscription/includes/class.ywsbs-subscription-order.php
    -> LINE 180 :?$new_cart->cart_contents[ $new_cart_item_key ][‘data’]->set_price( $current_price );

    The solution to avoid a server error in this case would be just adding a simple IF as I suggested.

    Thanks & best regards
    Norbert

    • This reply was modified 10 months ago by ngoels.
    Thread Starter ngoels

    (@ngoels)

    Hi Alberto (@witcher83) any news on that?

    Plugin Support Alberto Ruggiero

    (@witcher83)

    Hello @ngoels,

    as said the subscription cannot be with price zero because PayPal Standard (the only payment gateway supported by this version of the plugin) does not allow you to purchase them.

    So, we don’t plan to do any change in the plugin at the moment.

    Thread Starter ngoels

    (@ngoels)

    Hello @witcher83,

    I understand what you mean and I wanted to explain, that it even won’t be necessary to “trigger” payment when the price says “the product is free”.

    Sorry to read that you’re not going to fix the issue with just an harmless “if”. I would really appreciate it if you’re going to overthink your decision and have a closer look at my solution I’ve provided. That would by the way give your plugin an additional value when offering “free” subscriptions…. .

    …especially when it is not necessary to hack them in in two minutes after each plugin-update ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problem with Subscription Product which has a price of 0’ is closed to new replies.