• jpknz

    (@jpknz)


    Hi

    I’ve been using the plugin for a while and it’s great – saves a lot of time when modifying WC emails.

    I have a lot of custom code doing various things on my site which all works fine however today I was modifying a WC Subscriptions email and decided to use the Preview plugin again instead of waiting for emails to be sent/received and came across an issue.

    It seems that for a switch order with the switch completed email (NB haven’t tried for other type of orders or emails) that the plugin passes the subscription number rather than the switch order number. I’m sure there is a reason for this however what I was trying to test expects the order number as passed in to the switch completed email template. The email itself sends fine (passing the order number to the function to do it’s thing in the process) if triggered when processing an actual subscription switch but causes a fatal error when using the preview plugin.

    • This topic was modified 6 years ago by jpknz.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author digamberpradhan

    (@digamberpradhan)

    Hi jpknz,

    I’ll have to review that use case, but it’s probably due to how Orders are passed to subscriptions – specially in the switch case scenario. Please feel free to dig around yourself. I really don’t have time these couple of weeks and send me a pull request if you find a solution

    https://github.com/digamber89/woocommerce-preview-emails

    I will dig around when i have time.

    Thread Starter jpknz

    (@jpknz)

    Hi digamberpradhan

    Not sure how to do a pull request – might have a look at that later if I get some time.

    The offending code however I’ve located as below.
    woo-preview-emails\classes\class-woocommerce-preview-emails.php
    Lines 177-187 inclusive as below.

    } else if ( strpos($index, 'WCS_Email' ) === 0 && class_exists('WC_Subscription') && is_subclass_of($current_email,'WC_Email') ) {
    	/* Get the subscriptions for the selected order */
    	$order_subscriptions = wcs_get_subscriptions_for_order($orderID);
    	if (!empty($order_subscriptions)) {
    		/* Pick the first one as an example */
    		$subscription = array_pop($order_subscriptions);
    		$current_email->trigger($subscription);
    
    	} else {
    		$current_email->trigger($orderID);
    	}

    These lines get the subscription for the order to pass to the email templates however Woocommerce Subscriptions (WCS) expects the order number and does the subscription # lookup itself. Commenting out these lines and the results are as expected (including that the emails have both the order # and subscription #. This worked with the default templates and my modified ones.

    The exception to the above is that WCS seems to expect subscription number for the below emails. Commenting out the above lines will cause these emails (in this plugin – didn’t test actual sending of the emails) to throw exceptions.

    Cancelled Subscription
    Expired Subscription
    Suspended Subscription
    • This reply was modified 6 years ago by jpknz.
    • This reply was modified 6 years ago by jpknz.
    Plugin Author digamberpradhan

    (@digamberpradhan)

    Thanks @jpknz – I will try to get the changes made and pushed AS SOON AS I CAN.
    Been a bit flushed recently – but I will try.
    Thanks for digging in man.

    Cheers.

    Thread Starter jpknz

    (@jpknz)

    No worries.

    I’ve created code that works with all of the standard WC and the WCS emails. No idea on how to do a pull request or even if I have access to do that so you can find the updated file at
    https://1drv.ms/u/s!AjXczII8zGSUuB1Cq5vPe-cgn-Iv

    The edits are as below
    line 163 – array created of WCS emails that require subscription instead of order
    line 178 – else if changed to check if $index is in the array created on line 163
    line 180 – changed wcs_get_subscriptions_for_order to include parameter array of ‘order_type’ => ‘any’. This is because wcs_get_subscriptions_for_order defaults to order_type = parent which did not work for the orders I was testing on (for some reason – not sure why…they were standard renewal orders)

    While it works for me you should obviously test yourself before changing any code in the plugin particularly in relation to any other emails outside of standard WC or WCS (as those are the only woocommerce plugins I have).

    • This reply was modified 6 years ago by jpknz.
    Thread Starter jpknz

    (@jpknz)

    Hi @digamberpradhan

    Any update when this will be added to an update? I noticed a new version when out today.

    Thanks

    Plugin Author digamberpradhan

    (@digamberpradhan)

    Hi jpknz,
    I’ve been getting a lot of e-mails regarding 3rd party plugins lately.
    So i’ve decided to make the plugin more extendable. Currently i’m looking at providing support for bookings and subscriptions.

    This however – is taking a lot more time than I anticipated. The next plugin update WILL DEFINETLY have these changes built in.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WC Subscriptions – Sub number passed rather than order number’ is closed to new replies.