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?
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.
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?
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.
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 🙁
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. **
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?