Skip Navigation

[Resolved] How is possible to save it in the woocommerce cart meta?

This thread is resolved. Here is a description of the problem and solution.

Problem:

Using Toolset form commerce to submit the form and post custom fields, should be great to have the possibility to call this data in the Woocommerce cart page.

My partner don't have access to the backend and to my-order custom post, but only to the detail of woocommerce order.

Solution:

You can consider the Woocommerce filter hook woocommerce_cart_item_name, see details here:

https://toolset.com/forums/topic/how-is-possible-to-save-it-in-the-woocommerce-order-meta/page/2/#post-1117554

Relevant Documentation:

This support ticket is created 6 years, 2 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

This topic contains 22 replies, has 2 voices.

Last updated by domenicoS 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1115456

Data as number of people and number of child, ecc ar very important. How is possible to save it in the woocommerce order meta? should be great to have the possibility to call this data in the order detail and in the order email which my partner received automaticcally by woocommerce. My partner don't have access to the backend and to my-order custom post, but only to the detail of woocommerce order. At the moment in this detail there is only the finla price, they cannot know how many adults, childs acc.

#1115468

Hello,

As I mentioned in your previous thread:
https://toolset.com/forums/topic/booking-form-to-buy-a-product/#post-1114918

There isn't such kind of feature too, it needs custom codes, after user complete the payment, the "order" post will be created by Woocommerce plugin, you can use action hook "cred_commerce_after_order_completed" to trigger another PHP function, use it to save the data as order meta.

For example:

add_action('cred_commerce_after_order_completed','add_meta_to_order',10,1);
function set_post_upgrade($data)
{
    $cred_form_id = $data['extra_data'][0]['cred_form_id'];
    if ($cred_form_id == 24662) { // replace 24662 with your Toolset form ID
        $post_id = $data['extra_data'][0]['cred_post_id']; //post ID
        $order_id = $data['transaction_id']; // order ID
// get meta from post
	$adult_num = get_post_meta($post_id, 'wpcf-adult-number', true);
// save meta into order        
	update_post_meta($order_id, 'wpcf-adult-number', $adult_num );
    }
}

More help:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed

#1115487

Hi, thank you for your reply.

I try this code but no information like number of person are displyed in the cart summury and in the final order summury.

#1115617

That is only an example, you will need to customize the codes according to your website settings.

And I have tried it in your website, but after complete the payment, I don't see the order list here:
Dashboard-> Woocommerce
Where can I see the new order details, and you will need to register the custom fields(adult-number) to the Woocommerce post type "order".

If you still need assistance for it, please backup your website, then update this thread, I need to deactivate plugins/theme in your website.

#1115621

You can see the order here: hidden link

There is the list of the orders.

Can we schedule togher when you deactivate the theme-plugin. I can set the website ofline in to 10 hours from now.

Is it ok for you?

#1115637

Thanks for the information, I can see the problem in your website, the action hook cred_commerce_after_order_completed does not work in your website, please check these:
1) In case it is a compatibility problem, please deactivate other plugins, and switch to wordpress default theme 2017, and test again

2) If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1116028

Hi,

I tried to deactivate all plugins and change the theme. It does not works.
I tried to sent you the dump file but is to large (2.5 gb)
If you wnat you can work directly on the website beacause is offline for some hour or provide me a different way to sent you the zip file.
Thank you

#1116136

I am trying to debug in your website, please keep it offline for half an hour, thanks

#1116154

Here are what I found:
1) for the single product post, you are using layout "Tour Booking Page Layout":
hidden link

But there isn't Toolset form in it, but in the front-end:
it display the post form:
hidden link

Can you restore the layout "Tour Booking Page Layout" back?

2) The post form "Booking Form":
hidden link
in section "Post status when the payment status updates", you are using options:
Purchase processing: Pending review

But after I submit the form, and complete the payment, the new "Order" post is in "On hold" status, it should be a compatibility problem of your website.

3) Deactivate plugins and switch theme, I can not complete the payment, I see other error message.

And since your website isn't in English, I prefer to debug your database dump file in my localhost.

Please open the duplicator package file (ZIP file), find the database dump file( SQL file), and put it in your own google drive disk, and share the link in below private detail box. Thanks

#1116206

Thanks for the links, your duplicator package file is too big to download,

please try as I mentioned above,
Please open the duplicator package file (uwazcm0v-DirectAdmin-2018-09-26-12-25-14.zip), find the database dump file( SQL file), the file name is something like this:
dup-database__8c6ef4d-27031920.sql

and put it in your own google drive disk, and share the link in below private detail box:
https://toolset.com/forums/topic/how-is-possible-to-save-it-in-the-woocommerce-order-meta/#post-1116205

Thanks

#1116243

Ok, should be done. Please check the preview link a sent you with the last private post, is not changed. I upload only the sql file.
Please confirm me if ok

#1116312

Thanks for the details, I can download the file, will update here if there is anything found

#1116979

Here are what I found, it seems that you have changed a lots in your website

I have done below modification in your website:
1) Put the Toolset form "Booking Form" in layout
hidden link

It is required to use Toolset form to trigger the action hook "cred_commerce_after_order_completed"

2) Edit the post field group "order group":
hidden link
Add the existed field "adult-number" into the field group, you can add more other existed fields by this:
- click "Add New Field" button-> click "Choose from previously created fields" button
Those fields should be same as your form "Booking Form"

then you will be able to see the fields when you edit single "Order" post

3) Modify the PHP codes in your theme file "functions.php", from line 202 to:

add_action('cred_commerce_after_order_completed','add_meta_to_order', 999, 1);
function add_meta_to_order($data)
{
    $cred_form_id = $data['extra_data'][0]['cred_form_id'];
    if ($cred_form_id == 24662) { // replace 24662 with your Toolset form ID
        $post_id = $data['extra_data'][0]['cred_post_id']; //post ID
        $order_id = $data['transaction_id']; // order ID
// get meta from post
    $adult_num = get_post_meta($post_id, 'wpcf-adult-number', true);
// save meta into order        
    update_post_meta($order_id, 'wpcf-adult-number', $adult_num );
    }
}

You can add more fields in the PHP codes with get_post_meta( $post_id ... ) + update_post_meta ($order_id ...)

4) Test it in front-end:
hidden link
There are two forms in it, you should use the second one, which is the Toolset form "Booking Form"
- Fill the form, submit
- Complete the payment,
PS: it seems the calculation does not work due to your recent change, if you need more assistance for it, new ticket please.

5) Dashbaord-> Products-> Orders
hidden link
find the new order post, enable the checkbox before it, in the select "Bulk Actions", choose option "Change status to completed", click "Apply" button

6) Edit the new order post, you should be able to see the "adult-number" value is changed to be same as the new "my-order" post

For your reference, and in your website, there are lots of errors, for example:
hidden link

http://www.tripdoggy.com didn’t send any data.
ERR_EMPTY_RESPONSE

It is hard to debug in it. Hope it is clear

#1116996
sreenshot-01-01-01.jpg
sreenshot-01-01.jpg
sreenshot-01.jpg

Hi Luo,

Sorry but I think you are wrong. As I said in the previus post you have worked on a wrong layout, on a wrong field and on a wrong tour.

I give you a list with all the right item to work on.

The layout where I put the form is this: hidden link
This is the right layout to work on

And the product is this: hidden link

Also you are used I wrong group of field. I tell you in the post before that the group field used for the booking form is this: hidden link

I give you all the list in the last post beacuse the process is about thes items. The otherones are setting in a different way.

Until now it does not work . I cannot see the number of adult in the cart page, no in the checkout page and no in the order page

I share you the screenshot

#1117034

As I mentioned in my first answer, it is only an example for show you how to use Toolset form action hook "cred_commerce_after_order_completed" to achieve what you want.

I have tried it again in your website, it works fine, see the result order post here:
hidden link
field "Numero Adullti*", it is same value 3 as the my-order post:
hidden link

See details steps as I mentioned above:
https://toolset.com/forums/topic/how-is-possible-to-save-it-in-the-woocommerce-order-meta/#post-1116979

You just need to use the product URL you mentioned above to test again:
hidden link