Skip Navigation

[Resolved] Cred changing post data even if user doesn't complete checkout

This support ticket is created 6 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 10 replies, has 3 voices.

Last updated by Christian Cox 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1102615

Tell us what you are trying to do?

Charge for a post listing with CRED & Woocommerce

I have setup a new listing site whereby a user can create a listing & be charged for it via Woocommerce product ID.

In their "account" page i have provided the user the ability to upgrade a listing for a fee.

If the user upgrades a listing but doesnt complete the checkout/complete payments - the associated listing is still upgraded & saved.

Is their anyway to update the listing ONLY if the user completes the checkout process?

Is there any documentation that you are following?
How to Build WordPress Directory and Classifieds Sites using Toolset

The example of

Is there a similar example that we can see?

What is the link to your site?

#1103247

Could you check what you have set in Toolset > Forms > the_form_you_refer_to > Edit > Toolset Forms Commerce > Post status when the payment status updates > Purchase processing?

That should be "Pending Review" (or similar), so the post should be updated yes, but not published (hence not complete)

#1103257

Thank you - yes this is set to: pending review

In this particular instance I need the cred edit form to update the post information only if the checkout is completed - is this possible?

At present it looks like the cred form is edited > the post is updated/saved > WooCommerce checkout > post updated + paid for

However if the user doesn't pay + clicks the back button the post is still saved but not paid for

Any thoughts on this would be appreciated

#1103327

Just an update - I was thinking of doing this to combat this issue:

Add / enable revisions to post type used in form

Track specific field (showing the subscription type / Id based on WooCommerce Id)
https://toolset.com/forums/topic/revisions-tracking-custom-fields/#post-190229

Add notification email in cred form submission message like:

"check user has paid or revert back to previous revision"

Pending review - admin manually enable (publish) or if user hasnt paid revert to previous revision

I will test this scenario - do you foresee any problems doing it this way?

#1103763

Even with revisions active, the post connected to a Form is updated as soon as the Form is submitted with whatever changes have been made in the Form. If that's okay with you, then the solution you described could work. The only way to apply changes to a post after payment is to use the Forms Commerce API cred_commerce_after_order_completed or cred_commerce_after_payment_completed to programmatically make changes later in the Order lifecycle.
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed
If you'd like to discuss more details about that, I'll need some additional information about the post, and what exactly is being changed when you do the upgrade.

#1104366
post-forms.png
field-product.png
field-guide.png

Thank you - any solution or advice is more than welcome.

So in this instance I have a Custom Post Type called "Listings" which contains the listing fields (name, address, photos, location etc)

With a custom field called: "Subscription Selected" (slug "subscription-selected")

This contains the listing subscription type: (image attached)

The IDS are associated with the woocommerce products (image attached)

So when a user edits/upgrades their listing they can select the option "Renew for 30 Days" & proceed to the checkout
Post form (image attached)

This works as expected - the user clicks upgrade , the radio option is updated "Renew for 30 Days" and the associated fee is on the checkout.

The only problem is if they dont pay on the checkout the listing remains updated as the option "Renew for 30 Days" is selected.

Thank you for your time & consideration

#1104739

Okay instead of choosing the Subscription Selected field when the User edits this Listing post, let them choose an option in a generic field, something like this:

[cred_generic_field field='hidden-field-slug' type='select' class='' urlparam='']
{
"required":1,
"validate_format":0,
"default":[],
"persist":1,
"options":[
{"value":"775","label":"RENEW FOR 30 DAYS"}
]
}
[/cred_generic_field]

Use the generic field selection to set a hidden field value on the post with the cred_save_data hook, something like this:

add_action( 'cred_save_data', 'save_hidden_subscription_field', 10, 2 );
function save_hidden_subscription_field( $post_id, $form_data ) {
    if ($form_data['id'] == 12345 ) {
        update_post_meta( $post_id, '_hidden_purchase_field', $_POST['hidden-field-slug'] );
    }
}

Then use the cred_commerce_after_order_completed hook to change the actual Subscription Selected field using the hidden field value, something like this:

add_action( 'cred_commerce_after_order_completed', 'edit_subscription_field_hook', 10, 1 );
function edit_subscription_field_hook( $data ) {
    if( $data['extra_data'][0]['cred_form_id'] == 1128 )
    {
      $post_id = $data['extra_data'][0]['cred_post_id'];
      $hidden_purchase = get_post_meta( $post_id, '_hidden_purchase_field', true);
      update_post_meta( $post_id, 'wpcf-subscription-selected', $hidden_purchase ); 
    }
}
#1105368

Thank you for your help - i ran some tests but this wouldnt work for me with this current setup.

The problem being that the cred form states "Set expiration date for post created or edited by this form" set to 30 days.

So this would also have to be factored in to the code - for example user selects 30 day renewal, proceeds to checkout - doesnt pay - "subscription selected" not affected (by code above) - 30 days expiry still shows

I think for my project I will have to manually review each "listing upgrade" to ensure the right settings are being used for the users that have paid or if not paid.

I appreciate your time and advice & hope you guys continue to support and update the toolset service as its really very good - all the best

#1105549

I see, if you wanted something more automated you would have to set up a separate Commerce Form that is not actually connected to the original post that was created by Forms, but instead creates a new post. That new Form would include the field to select a purchase subscription, as well as a hidden field containing the original post ID for reference later. Then when the order or payment is completed, use the Commerce Forms API to programmatically update the expiration date of the original post based on the subscription purchased. That expiration date is specified as a Unix timestamp in a postmeta field under the key _cred_post_expiration_time.

#1105572

Thank you - Perhaps there is a better way to upgrade & renew listings than I'm using, as I think I have hit a limitation that would take it away from being a streamlined/easy setup

It would be useful to have a tutorial or guide to accommodate these features - if you or the team have any ideas that would be great.

#1105590

Manipulating existing post expiration dates based on WooCommerce purchases is a custom feature that isn't built-in to Toolset. It's not an easy thing to setup, but once it's in place it can be automated. My last comment was a high-level overview, and if there's a specific part of the process you want to discuss in more detail, I'm glad to assist with any code that touches Toolset APIs.