Skip Navigation

[Resolved] Displaying custom field in the cart and order

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

Problem:
Displaying custom field in the Woocommerce cart page and in the order page a few custom field, how i can do this ?

Solution:
you can edit the theme file for rendering the cart page, use Types function types_render_field() to render the custom fields created with Types plugin:
https://toolset.com/documentation/customizing-sites-using-php/functions/
You can also try with WordPress function do_shortcode() to render shortcodes:
https://codex.wordpress.org/Function_Reference/do_shortcode

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/

0% of people find this useful.

This support ticket is created 7 years 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)

Tagged: 

This topic contains 14 replies, has 2 voices.

Last updated by ThierryR232 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#585510

Hello,

I search for displaying in the cart and in the order a few custom field ; how i can do this ?

thank you.

#585722

Dear Thierry,

I assume we are talking about WooCommerce cart page, you can edit the theme file for rendering the cart page, use Types function types_render_field() to render the custom fields created with Types plugin:
https://toolset.com/documentation/customizing-sites-using-php/functions/

You can also try with WordPress function do_shortcode() to render shortcodes:
https://codex.wordpress.org/Function_Reference/do_shortcode

#586115

Thanks luo, I rewrite the cart.php file.

but i don't succeed to display à custom fields on this. Please, can you explain ?

#586533

It needs custom PHP codes, and I have already provided the document links:
https://toolset.com/documentation/customizing-sites-using-php/functions/

If you still need assistance for it, please provide a test site with the same problem, fill below private detail box with login details and ftp access, also point out the problem page URL and where I can edit your PHP codes, which custom field do you want to display. I need a live website to test and debug.

#586932

I have tried the credentials you provided above, but get this error:
This site can’t be reached
shop.thierryra*****.fr took too long to respond.

Please check it, thanks

#587783

Hi, i think that's now it's ok.

#587871

It is difficult to connect to your test site, I get same error message:
This site can’t be reached
shop.thierryra*****.fr took too long to respond.

Could you provide a copy of your website by follow our document:
https://toolset.com/faq/provide-supporters-copy-site/

And fill below private detail box with a downloadable URL for the duplicator package

#588355

Thanks for the details, I can download the files, here are what I found

1) Your custom theme file cart.php does not work, the cart in the front-end, display empty in the content area. So I create a new cart.php, by below steps:
2) Copy the original template file cart.php from Woocommerce plugin
\wp-content\plugins\woocommerce\templates\cart\cart.php
To your custom theme folder "generatepress_child":
\wp-content\themes\generatepress_child\woocommerce\cart\cart.php
Now the cart in the front-end works fine
3) Edit above theme file:
\wp-content\themes\generatepress_child\woocommerce\cart\cart.php
line 94, add below line:

socho: <?php echo types_render_field('socho', array('post_id'=>$product_id));?>

It will be able to display the custom field "socho" value, just after the product name.

As you can see in above PHP codes, you can add parameter "post_id" to specific the post(product) ID.

#588670

Thanks Luo, it's work.

Last thing please, for display the same field in the invoice, how i can do ?

#589002

It is a new question, please create a new thread for it, and describe detail steps for the question:
display the same field in the invoice
Where and how can I see the invoice?

Thanks

#589152

yes the same field in the customer's invoice.

#589307

I checked again in the duplicator package you provided, there is an order page in:
hidden link
But there isn't any "customer's invoice".

To avoid any more misunderstand, please describe detail steps for the question:
display the same field in the invoice
Where and how can I see the invoice?

Can you point out the problem page URL? thanks

#590647

sorry for the late.

in fact i want displaying the custom field (socho) in the customer's invoice withe this plugin :
hidden link

it's possible ?

#591058

I have already provide an example for you in above post for how to display the custom fields using PHP function:
https://toolset.com/forums/topic/displaying-custom-field-in-the-cart-and-order/#post-588195

For your new question:
in fact i want displaying the custom field (socho) in the customer's invoice withe this plugin
It is a new question, which is different from the original question of this thread:
https://toolset.com/forums/topic/displaying-custom-field-in-the-cart-and-order/

I am not familiar with the plugin "WooCommerce PDF Invoices & Packing Slips" you mentioned above, but it should be possible within custom PHP codes, if you still need assistance for it, please create a new thread for it:
1) describe detail steps to duplicate same problem
2) Where and how can I see the invoice?
3) Where and how do you want to display the custom fields?

#592376

Thanks Luo, i'll open a new thread.