Skip Navigation

[Resolved] CRED Forms not Sending Notifications that Correlate with Toolset Forms Commerce

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by zacharyL 5 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#1328401

I am trying to have the CRED form send notifications to registered users (post authors) and website admin when a transaction is completed and when a post reaches a set time before post expiration. Both of these functions are integral to proper functionality of the site.

After spending some time troubleshooting with the client, I've discovered that notification triggers that are supposed to be correlated to the Forms Commerce WooCommerce functionality are not triggering, and therefore the emails to not getting sent.

Currently I have three CRED forms that are using the Forms Commerce functionality that achieve the following items:

  • Initial post submission that results in a WooCommerce transaction
  • Abandoned posts in which the user submits the post form but fails to follow through with the WooCommerce checkout process, and then returns to it at a later time to finish it thereby resulting in a WooCommerce transaction
  • Renew or upgrade existing post that has either expired or the user simply wishes to upgrade to higher tier package, resulting in a WooCommerce transaction

The triggers that are currently not working as they should are:

  • When purchase status changes to "Completed"
  • "3 Weeks" before the automatic post expiration date

So a couple other things I've noticed:

1) Upon submission of the form, I have it configured to set the post status to "Draft", in the case the user fails to follow through with the WooCommerce transaction, however at the very bottom of the configuration settings, I have the "Post status when the payment status updates" option "Purchase complete" configured to set the post status to "Pending Review". The posts' statuses are not changing to "Pending Review" upon transaction completion.

2) Other notifications are operating properly. I have one set to trigger "When post status changes to 'Published'". This one works just fine.

It should be noted that we have this php snippet modifying the post expiration date on form submission:

add_action('updated_post_metadata', 'vk_set_dog_listing_expiry', 10, 4);
add_action('added_post_meta', 'vk_set_dog_listing_expiry', 10, 4);
function vk_set_dog_listing_expiry($meta_id, $object_id, $meta_key, $_meta_value)
{
    // Don't run this function when editing Dogs through Admin Backend
    // We only want this to run when using the "List Your Dog" and "Renew Your Listing" forms
    if (is_admin())
    {
        return;
    }

    $expiryMonthsMap = [
        '771' => 3,
        '772' => 6,
        '774' => 12,
        '775' => 3,
        '776' => 6,
        '777' => 12,
    ];

    if ($meta_key === '_cred_post_expiration_time')
    {
        $post = get_post($object_id);
        if (get_post_type($post) === 'dog')
        {
            $package = get_post_meta($post->ID, 'wpcf-package', true);

            $months = $expiryMonthsMap[$package];
            $time = strtotime('+'. $months .' months', time());

            update_post_meta($post->ID, '_cred_post_expiration_time', $time);
        }
    }
}

The logic behind this snippet is to configure the expiration date dependent on what package the user selects to buy.

  • Two packages last for three months
  • Two packages last for six months
  • and Two packages last for an entire year

As the form submission settings only allowed us set one expiration date, regardless of the package selected, we had to find a way to work around this. This was our workaround.

Not sure if it is interfering with normal operation, but the initial thought was that the notification triggers were reliant on the expiration date recorded in the post's meta, rather than what was set by the form. Are we wrong to assume this?

#1328621

There are issues in how Toolset Forms updates expiration dates which might affect you here.
Our goal is to make the post-expiration calculated starting when the associated order is marked as complete. Right now, unfortunately, this happens before! So theoretically a user can not pay, but still, renew his post thru an eventual edit form.
There are plans to change this but nothing yet concrete to share as a solution.

Also, no notifications will be sent by Forms which have the "Charge Payment with this Form" checkbox checked.
More precisely, if "Forms Commerce" section on a user form is set to "Charge payment with this form", then, an email notification set to be sent "When a new user is created by this form" does not trigger.

Then there was this issue, https://toolset.com/errata/cred-commerce-emails-sent-order-status-changes-instead-specific-order-status/, but this is resolved meanwhile.

I will download your package now, see if any of the above relates to it.
I'll be back with findings ASAP.

#1328687

After deploying the duplicate, logging in figures in an E500.
The error is:

Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes) in /types/vendor/toolset/toolset-common/expression-parser/parser.php on line 303

There is a memory issue (and my local server has enough memory), which seems to be consumed in Types, but it could happen anywhere, depending on which action comes last.

This happens even before I can see the login form, so it should be an issue on your side as well.
I was only able to reach the login screen, once I disabled the Types Plugin.
Then I could log in to the site, and was actually able to re-activate Toolset Types without related errors.

I see you have these Forms:
Canine Registration
Edit Abandoned Canine Registration
Renew or Upgrade Profile

Let me see if I understand all issues correctly:
1. When submitting Canine Registration, the post is "draft", but not paid immediately, and then later paid, it does not update to "Pending review".
2. The several email notifications (When post status changes to, X before the automatic expiration date and When the purchase status changes to) do NOT work IF the Form applies for payments? Is this correct?

To test this, I started with the Canine Registration Form, aborted payment, and completed it later using Edit Abandoned Canine Registration.
I installed a Mail Logging Plugin to track the mails and observed the statuses set.

I disabled ALL plugins but Toolset/WooCommerce, and used Theme Nineteen for these tests, for simplicity.

When submitting the Form (before paying, but after it redirected to the checkout), the new Dog is visible as a Draft in the backend.
I chose the Standard Listing ($27 for 3 Months)

No email is sent at this point as expected, but note, the Expiration date is already set, even the client did not yet pay-

The main issue here clearly is, the expiration date is set to 1st September 2019, but you say to send the notification 3 weeks ahead of expiration, so nothing can ever be sent (1st September is in one day, 3 weeks trigger is past).
I see you solve that with custom code on your site, and you update that EVERY time a field is added or updated.
I would suggest rather hooking this to a Toolset Forms API hook, for example cred_save_data or similar, so it's fired just once:
https://toolset.com/documentation/programmer-reference/cred-api/

I did not test your custom code locally, instead, I changed expiration dates to something testable (2 hours) and the notification to one hour ahead of that. I also changed to check every 5 minutes instead of daily.
Then I repeated the tests.

Again, before purchase a draft is created, no email sent, as expected.
The emails of this form say to be sent if the post is published before it expires, or when purchase changes to complete.

Hence I now purchased the product.
Of course, I had to disable Paypal, I cannot test this otherwise, so I used check payments.
I placed the order, at this point the email of WooCommerce is sent.

When I now complete payment, the emails of Forms are sent:
ATTN: Action Required! Dog Profile Registered (because the payment changed to complete), and again the WooCommerce email.

The Dog is Pending Review, correctly, and the notification for When post status changes to is not fired.
As soon I publish, it is fired.

Remains to wait for the expiration email, which should be fired from now on in about an hour.

Note, I updated the payment status in the backend, by editing the very order - you cannot do it within the orders list with the bulk actions, but need to edit the very order and set it to complete (so it fires the action as Forms listens to and updates the Post Status).

As far I see yet, this issue is likely due to another software or plugin, since with above tests until now all worked as expected.

Please do not hesitate to correct me if I am wrong in any of the steps.
I will udpate you here on expiration notifications as soon I receive (or not) it.

#1345141

Oh gosh, I had totally forgotten about this when I got pulled away onto other projects.