Skip Navigation

[Resolved] Change Product Status works but not as expected.

This support ticket is created 6 years, 4 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
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 4 replies, has 3 voices.

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

Assisted by: Christian Cox.

Author
Posts
#957469

I have created a form where admin can edit the order status.

i have created generic field includes all WC statuses:

      [cred_generic_field field="post_status" type="select" class='form-control' urlparam="" output='bootstrap']
      {
      "required":0,
      "validate_format":0,
      "default":["[wpv-post-status]"],
      "options":[
      {"value":"wc-pending","label":"pending payment"},
      {"value":"wc-processing","label":"processing"},
      {"value":"wc-on-hold","label":"on hold"},
      {"value":"wc-completed","label":"completed"},
      {"value":"wc-cancelled","label":"cancelled"},
      {"value":"wc-refunded","label":"refunded"},
      {"value":"wc-failed","label":"failed"}
      ]
      }
      [/cred_generic_field]

and then i have added a code snippet to save the order status when submitting the order form:

// CRED PUBLISH STATUS
add_action('cred_save_data', 'Select_Post_Status_func',10,2);
function Select_Post_Status_func($post_id, $form_data) {
 
   
  if($_REQUEST['post_status'] == ''){
  //Do nothing
  return;
  }
   
  //create an array of values with all ID's of the Forms you want to check:
  $ids = array("101","102","103","3357");
    
  //Check if the current form ID is one of in the above array:
  if (in_array($form_data['id'], $ids) ){
   
  $my_post['ID'] = $post_id;
  $my_post['post_status'] = $_REQUEST['post_status'];
  // Update the post into the database
  wp_update_post( $my_post );
  }
}

now after editing the order status on the frontend and changing the order status as needed, the order changes the actual status e.g. from "wc-on-hold" to "wc-completed", and then i can see this change in the backend.

But the problem is, it doens't really change anything else than the status. WooCommerce normally send a notification for the Customer that the order status has changed to "completed" or "Refunded" etc... it looks like only when i change the status of an order on the backend then the email notification will be sent to the customer but changing the status with cred doesn't send anything.

also i noticed that Order Notes in the Order on the Backend doesn't show a new Note when changing the status with Cred (e.g. Order status changed from Pending payment to Completed.)..Notes and Notification get updated only when updating order status on the backend but with Cred forms, it changes only the status but no order Notes or Emails sent to Customers.

How can i change the order status on the frontend properly so that Order Notes and E-mail Notifications works as expected?

here is the Order listing: hidden link

If you click on the pencil icon to edit the order, you can change the status and save it. then check on the frontend the order status has changed.
on the backend also changed but no Notes and no Notification to email.

here is edit order form : hidden link
here is the Code Snippet: hidden link

#957926

Well, WooCommerce performs probably a lot more actions than just updating the $my_post['post_status'] when you work with Orders, and all those actions you will need to hook to your code which fires at cred_save_data()

But with this we cannot help, it's related to the 3rd party API.
If WooCommerce for example offers an API to fire a order or manipulate it with PHP, then you can use that within the cred_save_data() and it'll do what it would be supposed to do.

Toolset Forms is not intended to manipulate Orders, and even WooCommerce Products are a little restricted with Forms:
https://toolset.com/documentation/user-guides/creating-woocommerce-products-using-cred-forms/

Creating and editing Orders is totally another task, and usually, not needed as that is exactly what WooCommerce does, it provides a method to manipulate it's orders just fine.
When you "duplicate" this same to Toolset Forms, then you need to take in account all the "magic" that WooCommerce does for you in the background when you update the post_status of an order

With Toolset Forms you can for example send notifications from the form itself, when you edit the Form, you can add notifications and they will be sent at the set conditions.
But it is not suggested to do that, Toolset Forms is not intended to be a Front End replacement for WooCommerce.

The major focus of Toolset, or ability, related to WooCommerce, is it's design of Single Products and the Shop, and the payments you can add to forms with it, but it doesn't intend to "do what WooCommerce does in the backend" - in the front end.

If WooCommerce would/will intend that the Orders (or others) should be manipulated in the Front End, it would probably be of best quality if made by WooCommerce.
Toolset Forms is not a perfect choice for this as because it is limited in the interaction with WooCommerce's data structure, and does not integrate in such particular events like the Order Manipulation in the backend, unfortunately.

I can add a feature request, but I can tell that this has a lower focus, the major focus is on the design of the WooCommerce Data, and it's junction with Forms Commerce where you can cover payment on forms.

Please let me know if you know of any API that WooCommerce offers to manipulate the Orders "completely", we still help when it comes to troubles using that in a cred_save_data().

#957927

BTW, if you plan to hook on any "WooCommerce" event, Toolset Forms offers a set of API if you use Toolset Forms Commerce:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/

But, that is only applying to Forms, that either create Posts or Users, and use a payment connected to WooCommerce Products.
It does not allow you to edit Orders, or manipulate them, but to hook in when they are manipulated in the backend as WooCommerce intends.
On such example is:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed

This will happen after the order is complete.
But, the completion of the order is something that WooCommerce does on it's own and Toolset cannot control that.

#957961

First of all Thank you for the great explanation and time, i really appreciate that.

I can fully understand what is the purpose of Toolset now and i find it also great fit. but we non-developer, want always more. I can honestly see that Toolset is more than what is made for, i have created a great website and management system for orders and products of WooCommerce and Users which is all can get managed from the Frontend, with your support and extra code snippet where Toolset is not 100% supporting. for example Orders are not fully supported yes but i managed to edit order details, and billing information from the frontend without extra code.. only with Toolset Plugins, which makes Toolset more powerful when you dont want that user get to the backend..

so as i understand, this is possible with API of WooCommerce. so i have made a quick research and found WooCommerce Rest API offered by WooCommerce : https://docs.woocommerce.com/document/woocommerce-rest-api/

am i on the right direction?

i have watched also this video, sounds like trough this API user can modify order/product/etc data. this is actually then what we need to changes post status properly on the frontend..right?
hidden link

let me know your opinion about this so i can continue digging for a solution. because this is one of the last steps of development of the website i am doing, and i indeed need this option to be done from the frontend, since i dont want that user go to the backend.

#958344

Hi, you can probably use their standard PHP API. Here's a sample:
https://stackoverflow.com/questions/22935358/woocommerce-change-order-status-with-php-code

Here's more documentation:
https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html

Here's a link to their support forums, where you can ask more technical questions about how to modify Order statuses using PHP: https://woocommerce.com/my-account/create-a-ticket/

Once you know how to update an Order status from a technical perspective, I can assist you with any Toolset APIs you need to use to trigger that update.