Sauter la navigation

[Résolu] Retreive custom fields in checkout page

This support ticket is created Il y a 6 années et 2 mois. 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)

Marqué : 

Ce sujet contient 8 réponses, a 2 voix.

Dernière mise à jour par Pat Il y a 6 années et 2 mois.

Assisté par: Christian Cox.

Auteur
Publications
#1145804

Pat

Hello,

I have a WC site with Toolset and have defined a WC Cred in order to buy product. This Cred has some additional fields in it and I would like to retrieve them in the checkout WC page.

For this, I'm using the Checkout Field Editor plugin and the hook provided by this plugin :

function custom_override_checkout_fields ( $fields ) {
$fields['billing']['test_radio']['default'] = 'one';
return $fields;
} // End custom_override_checkout_fields()

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

that enables to put a specific value in the checkout field.

Now, my issue is to retrieve the fields from the Cred and place them in this kind of hook.

Let say I have a field (wpcf-date-de-debut) which is a radio field and I want to retrieve its value inside the hook.

How can I do this?

Regards
Pat

#1146061

I can show you how to get a custom field value from a post created by Forms. You need to know the Order ID. Let's say the Order ID is 12345:

$order_id = 12345;
$forms_post_id = get_post_meta($order_id, '_cred_post_id', true);
$debut = get_post_meta($forms_post_id, 'wpcf-date-de-debut', true);

Then the $debut variable would contain a Unix timestamp like1542141458.

The problem is how to get the Order ID on the checkout page? I'm not sure, you need to consult the WooCommerce documentation for that information.

#1148419

Pat

Hi Christian,

Thanks for the info.
I have made some search concerning Woocommerce and did not found anything relevant to retrieve the order ID at that stage.
I was thinking that due to the strong integration between Toolset and Woocommerce, this would be something easily available within Toolset?
Regards
Pat

#1149303

Toolset doesn't directly control anything on the checkout page, despite strong integrations in other areas. This is one reason why you had to use a separate plugin to add custom fields. Unfortunately Order ID is not available in any Toolset APIs when the site User visits the checkout page.

A quick search led me to this article: https://stackoverflow.com/a/37701301

#1149724

Pat

Hi Christian,

Thanks for your search.
Perhaps, the best would be to come back to my initial aim. I need to add in the cart and checkout page and mails some info concerning Toolset custom fields that are linked to the product (and then, to the WC Cred that define the product)
So, as a first solution, I tried to use the Checkout Field Editor plugin (that integrates the fields automatically in the crat and checkout page). Saying that, the issue there was to affect the fields created by this plugin with the value entered in the Cred form.

As it seems to be difficult to retrieve the order ID in the checkout page, perhaps the best is to use WC hooks to add info to the cart, checkout page and mail.

Do you have any idea on what are the needed hooks for this and how they can be used with Toolset custom fields? And also, will it be possible to retrieve the needed info whatever the page we are (cart, checkout ...)
Regards
Pat

#1150090

Toolset is not set up to help you add to the cart page, the checkout page, or emails generated by WooCommerce, so I don't have this kind of technical information available. You need help from WooCommerce support or the WooCommerce community. Once you have the Order ID, I can show you how to use that to get the custom field value.

#1152439

Pat

Hi Christian,

I'm OK with what you said. May I suggest that this is integrated in the todo list in order that Toolset is able to provide the right information in the cart or checkout page in the future?

Regards
Pat

#1152683

Yes of course, please submit a new ticket in the forum using the "Suggest an improvement" option. It will be logged as a feature request, and our developers may decide to implement it in the future.

#1153111

Pat

Hi Christian,

Sure, I will follow your advice and create a specific topic for adding this feature inside Toolset.
Thanks
Pat