With this hook, it has the product_id and based on the product ID, you can get the value of your custom field and it also offers the psot_id. So, what if you try to use the hook and based on the product_id get the value of your desired custom field and then assign it to your post based on the post_id.
Relevant Documentation:
This support ticket is created 2 years, 11 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.
I am using Toolset and Woocommerce and currently have a little function working nicely to save data in a custom field when an order is created. This is that snippet:
However, I would like to copy across to the order a custom field value of the product being purchased instead of a specified static value on this line:
Hello. Thank you for contacting the Toolset support.
However, I would like to copy across to the order a custom field value of the product being purchased instead of a specified static value on this line:
$forced_value = 'TEXT-TO-SAVE-IN-THIS-CUSTOM-FIELD';
==>
Could you please share bit more details as its not clear to me what value you want to assign at and when. When you say copy across to the order, what you mean, do you mean that you have added multiple products to single order and then you want to assign some value?
Good point re multiple products. So, whether there are multiple 'simple' products in the order or not, I have a custom field in all products and, if it is NOT empty, then copy or add the value of that custom field to a custom field in the order. Does that make sense?
Its still not clear to me what value you would like to copy of what field to what field.
Do you mean that if the value of your custom field is empty, you want to copy the value for that custom field from the existing order. So, if the custom field is empty, we should search for any existing order and get the field value and assign it to this new post. is this correct?
Ok so let's say we have a woo product post that includes a custom field - [types field='PRODUCT-CUSTOM-FIELD'][/types] - which is sometimes empty and sometimes not depending on the products in the cart at checkout.
As usual, on the product post the customer chooses the number of items, goes to cart and then to checkout.
On successful payment the order is created and notification sent to the customer.
At this moment of successful payment and creating the order I would like to save the value of that custom field from the product if the field is NOT empty to a specified custom field in the order - [types field='ORDER-CUSTOM-FIELD'][/types].
The code I have above does exactly this except it specifies what value to save to the order's field.
I want this code to get the value from the products in the order...
So. Save the product's custom field value - [types field='PRODUCT-CUSTOM-FIELD'][/types]
to an existing custom field belonging to the order - [types field='ORDER-CUSTOM-FIELD'][/types]
With this hook, it has the product_id and based on the product ID, you can get the value of your custom field and it also offers the psot_id. So, what if you try to use the hook and based on the product_id get the value of your desired custom field and then assign it to your post based on the post_id.