[Closed] [CRED Commerce] Post status change doesn't work

This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Related documentation: Front-end Content Submission and Editing Forms

This topic contains 8 replies, has 2 voices, and was last updated by  Luo Yang 4 months ago. The support staff assigned to this topic is Luo Yang.

Viewing 9 posts - 1 through 9 (of 9 total)
Author
Posts
#558302

I have a CRED post creation form. The form saves post as draft once submitted. I want the post status to be changed to "pending" when a WooCommerce order is created, so in the CRED Commerce settings I have set "Purchase processing" to "Pending Review". But it doesn't work. The post status remains "draft".

So I made a little test:

add_action('woocommerce_checkout_order_processed', function ($orderId) {
  $order = new \WC_Order($orderId);
  $adId  = (int)$order->get_meta('_cred_post_id', true);

  wp_update_post([
    'ID'          => $adId,
    'post_status' => 'pending',
  ]);
});

This code changes the post status to `pending` when WooCommerce checkout form is submitted. And I found then even if I change the status to `pending` (or whatever) then CRED Commerce changes the status back to `draft`. I did a test with CRED Commerce enabled and disabled (I've disabled it once I reached the checkout page).

When CRED Commerce is disabled then the status remains `pending`. When the plugin is enabled then the status is reverted to `draft`.

So it seems that CRED Commerce does something, but it looks like it always changes posts status to `draft`. No matter what is set in the plugin's options.

All Toolset plugins are up to date.

#558337

Update:

I also tried to use `woocommerce_order_status_pending` and `woocommerce_order_status_on-hold` hooks with high priority (CRED uses priority 100, I used 200) in order to change the status programmatically on my own. But it doesn't work. Same issue as before - CRED Commerce is changing the posts status afterwards back to `draft`.

What hooks should I use in order to execute my code after CRED Commerce?

#558478

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

Supporter Timezone: Asia/Hong_Kong (GMT+08:00)

Dear lapalaZ,

For action "woocommerce_order_status_pending", please try with CRED built-in action hook:
"cred_commerce_after_order_received", it is locate in the cred_commerce plugin file \cred-commerce\classes\Form_Handler.php, line 548~549:

					// HOOKS API
					do_action( 'cred_commerce_after_order_received', $data );

same as above:
For "woocommerce_order_status_on-hold", please try with CRED built-in action hook:
"cred_commerce_after_order_on_hold", it is locate in the cred_commerce plugin file \cred-commerce\classes\Form_Handler.php, line 721~722:

					// HOOKS API
					do_action( 'cred_commerce_after_order_on_hold', $data );
#558485

@Luo Yang

Thanks. I've already tried these hooks and it doesn't matter if I use WooCommerce hooks with a high priority or CRED hooks - the result is the same - my code executes AFTER the CRED code. This is fine - I can see that the post status is updated properly (by my code), but something happens afterwords and overwrites the posts status back to `draft`.

So it works this way:
1. WooCommerce hook executes
2. CRED does stuff
3. CRED executes `cred_commerce_after_order_received`, `cred_commerce_after_order_on_hold`, etc
4. My code executes (status is set to `pending`)
5. Something happens and sets the status back to `draft`

So as you can see it doesn't matter if I use CRED hooks, or WooCommerce hook (with a higher priority than 100). Numer 5 always executes later. I dug a little in the CRED code, but I wasn't able to find what is it and when it executes.

---
But even if this solution worked fine then the bug reported in the first post still exist. Please pass this bug report to CRED developers.

#558500

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

Supporter Timezone: Asia/Hong_Kong (GMT+08:00)

The problem you mentioned above is abnornal:
5. Something happens and sets the status back to `draft`

We need to know if there is any compatibility problem in your website, please try this:
deactivate other plugins and switch to wordpress default theme, and test again, if the problem still persists, please provide a database dump file of your website, and point out where and how can I see the problem.

#558888

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

Supporter Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, I can duplicate same problem in my localhost, will feedback if there is anything found.

#559050

Good to know.

PS
In my previous post, I've asked to make the post public. I've accidentally posted it as private. It might be helpful for other CRED users.

#559438

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

Supporter Timezone: Asia/Hong_Kong (GMT+08:00)

I can not switch the your post to public, so I copy them here:

When the CRED Commerce plugin is disabled then everything works fine. The status changed to `pending` (by the code I've posted before) remains `pending`. The status is set to `draft` only when the CRED Commerce plugin is activated.

I made the test this way:

- Created a post by CRED (All toolset plugins were enabled)
- Reached the WooCommerce checkout page
- Disabled CRED Commerce (I did this is at this stage because I wanted the product to be added to cart by CRED Commerce, and CRED Commerce post meta to be saved on the order record)
- Submitted the checkout form
- My code (the same code that I've pasted in my first post, before but using the `woocommerce_order_status_pending` with priority of 200) updated the post status to `pending`
- The status remained `pending`.

When I do the same when the CRED Commerce plugin is activated then the status is changed back to `draft`. No matter if I use `woocommerce_order_status_pending`, `woocommerce_order_status_on-hold` or CRED hooks.

---
PS. I've accidentally made this post private. Please make it public again. I will not share any confidential data here.

#559866

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

Supporter Timezone: Asia/Hong_Kong (GMT+08:00)

CRED Commerce can update the status of the post, created by the form, when the payment status changes. This will let you automatically publish and hide posts when payments complete or are cancelled:
Purchase processing (In your case, you should setup the post status settings here)
Purchase complete
Purchase refunded
Purchase cancelled

But you mentioned above:
so in the CRED Commerce settings I have set "Purchase processing" to "Pending Review". But it doesn't work.

This is abnormal, which I can not duplicate same problem, please try these:
1) You are using the latest version of CRED plugin + CRED commerce plugin + Woocommerce plugin
2) deactivate other plugins and switch to wordpress default theme, and test again
3) If the problem still persists, please provide a database dump file (ZIP file) of your website in below private detail box, I need to duplicate same problem and debug it in my localhost, thanks

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘[Closed] [CRED Commerce] Post status change doesn't work’ is closed to new replies.