Hello,
I'm coming back to the previews ticket : https://toolset.com/forums/topic/post-dont-publish-everytime-after-order-payment/
I have just integrated the code as specified by Christian but I'm still getting the same issue : only the first product is published (on the 3 I have placed in the cart, the 2 others are draft).
Any idea on what could be the issue ?
Regards
Pat
Not sure what the problem could be, but I will take a closer look if you provide login credentials in the private reply fields. Please let me know where to find the Form on the front-end of the site, and where to find the cred_commerce_after_order_completed code.
- You can find the ADD TO CART button for example in this pages :
/produit/atelier-histoire-contemporaine-lundi-10h30-2021/
/produit/atelier-sagesses-des-jardins-vendredi-10h30-2021/
/produit/cours-chinois-b1-lundi-18h15-2021/
I cannot see the Add To Cart button anywhere on these pages, unfortunately. I checked the Produit template here:
hidden link
I see the Inscription Enseignement Form inserted in one of the text modules but it is inside conditionals:
{!{wpv-conditional if="( $(wpcf-type-d-evenement) eq 'Ateliers' ) OR ( $(wpcf-type-d-evenement) eq 'Langues' ) OR ( $(wpcf-type-d-evenement) eq 'Informatique' )"}!}
{!{wpv-conditional if="( $(wpcf-annule) ne '1' ) AND ( '{!{wpv-post-field name='_stock'}!}' gt '0' ) AND ( '{!{wpv-current-user info='logged_in'}!}' ne 'false' ) AND ( $(wpcf-date-prevente) lte 'SECONDS_FROM_NOW(0) ' )"}!}
{!{wpv-conditional if="( remplacement_role() ne '0' )"}!}
I don't know exactly what all these conditionals test...do I need to be logged in as a different User to see the Add to Cart button? Or is there a different Product I should try?
I probably need to create a clone of the site to run additional tests in my local environment without causing changes in the live site. Let me know if that is a problem.
Hi Christian,
I have started to migrate the site under a test site in order for you to be able to make any modification from your side.
Please allow private answer and I will pass you all needed info.
Just concerning the conditional tests, they have been placed for differencing the type of event, then take into acount the fact that the even is still opened, allow the ADD TO CART from a specific date in the future and last, be sure that the member has a valid yearly subsciption (remplacement_role function).
In the test site, I will not place those conditional test !
Regards
Pat
Okay thanks for the additional information. I have activated private reply fields for your next communication.
Hi Pat, I'm still investigating this. Can you tell me which Order number you were testing with when you said...
I have just integrated the code as specified by Christian but I'm still getting the same issue : only the first product is published (on the 3 I have placed in the cart, the 2 others are draft).
I would like to inspect the data in the database to see which posts are associated with the order, and which posts are connected to the Form submission.
Hi Christian,
The last order is 20688 with 3 different products inside. Only the first one have been publish. The 2 other have been published manually. All 3 have been paid !
Not sure if the issue is the same if you validate an order manually in the backend. This would help you to place an order an validate it in the backend (for this, you just have to add a check payment or a bank payment in the WC parameters).
Hope this helps
Regards
Pat
The last order is 20688 with 3 different products inside.
This order status is still marked "Processing". If the order status is not "Complete", the script I provided would never run. Only when the Order is "Complete" will the script publish the posts created by Forms. You can manually change the Order status to "complete", and I suspect that will publish all 3 posts.
I've made one change in the Form here:
hidden link
I've set the post status to be "Draft" during "Purchase processing". It was previously set to "Publish", which I think could be part of the problem. (screenshot) None of these posts should be published until the order is complete. I think you were seeing one published post even before the Order was complete, and this was part of the confusion.
I've also turned on the option "Cash on Delivery" in WooCommerce Payment settings so I could run a quick test in your staging environment.
Next, I visited this Product and clicked "Ajouter au panier":
hidden link
Then I visited this Product and also clicked "Ajouter au panier":
hidden link
Then I visited a third Product and clicked "Ajouter au panier":
hidden link
My cart had 3 products (screenshot), and 3 Ins Enseignement posts were also created in draft status (screenshot).
I checked out by selecting Cash on Delivery as the payment method. Order #20737 was created and I found it in Processing status as expected in WooCommerce > Orders. I selected that order and manually changed its status to "Complete" (screenshot).
Now all 3 Ins Enseignement posts associated with the Order are automatically Published (screenshot) by the script I provided. So the flow seems to work well in this case. Hopefully changing the Processing status has solved the problem completely. I will stand by for your update. If you are able to replicate the problem, please show me step-by-step how to recreate it.
Hi Christian
Many thanks for your time.
I'm a little confused with the order status.
I was not using the "completed" status due to the fact that after the payment, the order status is "In progress" and I don't want to have another manual action to transfer it to "Completed". That's why I chose to publish the post during the order processing, otherwise, it would not be published after the payment. I think this could be because the system is waiting for the delivery, but there is no delivery on the products on this site !!!
Could you give me some advice on that?
I will make some test in the next days to verify that all posts are published and keep you informed of the result.
Thanks again
Pat
I was not using the "completed" status due to the fact that after the payment, the order status is "In progress" and I don't want to have another manual action to transfer it to "Completed".
Forms Commerce works on the Order "Complete" status, because a "Processing" Order is still pending fulfillment. This becomes especially important when the Products involved are not virtual.
https://docs.woocommerce.com/document/managing-orders/
So the "Complete" Order status is a requirement for the entire Forms Commerce publishing process to work effectively from end-to-end, so you will either need a manual action or a 3rd-party plugin to adjust the Order status automatically once payment is complete. Otherwise, one or more of the posts created by Forms Commerce may be published, even if the User abandons the payment process. That would effectively allow Users to create free posts by starting an Order, but never submitting payment.
Some payment methods, like Paypal, do not automatically adjust the Order status once payment is complete. I suspect that is the case with whatever payment method you have been testing with. I understand there are custom code solutions for this, and also 3rd-party plugins that can automatically change the Order status for you when payment is complete.
https://www.tychesoftwares.com/how-to-automatically-complete-woocommerce-orders-when-they-go-to-the-processing-status/
https://toolset.com/forums/topic/publish-status-doesnt-change-after-payment/#post-915028
Our documentation refers to similar observations in these lessons:
https://toolset.com/course-lesson/charge-users-for-submitting-content/#3-1-updating-the-post-status-when-the-payment-status-updates
https://toolset.com/course-lesson/charge-users-for-registering-premium-accounts/#4-after-payment-is-completes-woocommerce-updates-the-order-status-and-users-return-to-the-sites-order-received-page
Hi Christian,
Understood !
I've pick up the code you proposed (even if I'm not using the "cash on delivery" method) :
add_action('woocommerce_order_status_changed', 'ts_auto_complete_by_payment_method');
function ts_auto_complete_by_payment_method($order_id)
{
if ( ! $order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ($order->data['status'] == 'processing') {
$payment_method=$order->get_payment_method();
if ($payment_method!="cod")
{
$order->update_status( 'completed' );
}
}
}
Just a last question on this : as I will have 2 different hooks (one for the order completion and another for the multi published posts), is there something to manage in order that everything go in the right way (ie : the hook on completed order should be fired before the one for the published posts).
Let me know.
Regards
Pat
I don't think there is anything else you need to do, because the cred_commerce_after_order_completed hook will only fire when the order is complete.
Hi Christian,
Thanks for the confirmation. I will make some additional tests in the end of August. If anything goes wrong, I will open a new topic.
Thanks again
Pat