Skip Navigation

[Closed] Change taxonomy after purchase (Toolset Forms Commerce)

This support ticket is created 3 years, 9 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by Jamal 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1946997

I’m creating a classifieds site using the toolset + Toolset Forms Commerce.

I want to enable payment for an advertisement already added (via the ad editing form).

Is it possible for a custom taxonomy "promoting" to automatically change from “no” to “yes” after purchase of promotion?

#1947279

Hello and thank you for contacting the Toolset support.

Yes it is possible using some custom code hooked into the cred_commerce_after_order_completed action.
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed

Given the taxonomy "promoting", something like this should work:

add_action( 'cred_commerce_after_order_completed', 'switch_ads_promoting_terms', 10, 1 );
function switch_ads_promoting_terms( $data ) {
  // which order was completed?
  $order_id = $data['transaction_id'];
  // which posts were created in this order?
  $all_order_posts = get_post_meta( $order_id, '_cred_post_id');
  // loop over all the created posts
  if( !is_array( $all_order_posts ) )
    return;
  foreach( $all_order_posts as $post_id ) {
    // switch the term
    wp_set_post_terms( $post_id, 'yes', 'promoting' );
  }
}

- https://developer.wordpress.org/reference/functions/wp_set_post_terms/

I hope this helps. Let me know if you have any questions.

#1951383

Than you for your help. I will try it.

And would it be possible for this taxonomy to change itself after a certain period of time, e.g. 1 month?

#1951415

That may be possible using a scheduling system. For example, you can make the post that is created by the form to expire after a month, then hook into it and change the taxonomy of the post.
https://toolset.com/course-lesson/setting-up-automatic-post-expiration/#customizing-automatic-post-expiration-using-filters

However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason, I have to kindly ask you to open a new thread if you need further assistance with this second question.

I am setting this ticket as waiting for your feedback until you get the time to try the custom code.

#1952327

I pasted the given code into Toolset > Settings > Custom Code, but when I buy promotion of Lowisko (its my custom post type) (and mark it in WooCommerce as completed) nothing happens 🙁

#1952335

Please make sure that the snippet is marked as active. Check this screenshot hidden link

If that's not the issue, can you provide the exact steps you follow in this process? Something like:
1. I go to xxx
2. I do xxx
3. I expect to have xxx
4. Instead, I get xxx

What payment gateway you use? Is the order completed at the end of the payment or on the backend?

I would also like to get access to your website to check all of this closely. If you would agree, your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1958237

Thank you for the credentials, I confirm that they are working for me.

I am not sure what do you mean by "the post disappears from the list" in step 9? What list? Can you share a URL where we can see it?

Maybe, it is because the post changes the status, or because it changes the author, check this screenshot hidden link
I believe that you don't want the author of the promotion to be set to the buying user, right?

On the other hand, in order to debug why the custom code does not work, I'll need to take a copy of your website and debug it locally. Please let me know if that's fine with you?

The topic ‘[Closed] Change taxonomy after purchase (Toolset Forms Commerce)’ is closed to new replies.