Skip Navigation

[Resolved] Adding text attribute to a product when adding it to cart using CRED form.

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

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#919045

Hi support team.

Apologies if this ticket covers third party plugins as well as toolset - I'll try to explain as fully as I can what I'm trying to do...

I have Woocommerce, Toolset and CRED commerce set up.
I have a Custom post type called Tools.
I have a CRED form - on each individual Tool the user can fill out the form to upgrade that tool to a featured tool.
When they submit the form it adds a product to the cart.
The product is called "Featured Tool Listing" and the same product is used to upgrade any tool.
The user then checks out and the Tool post is updated to make it a featured Tool.

This all works well, but when a product is ordered there is no way to know from looking at the order which Tool was upgraded. The order just shows that "Featured Tool Listing" was ordered but doesn't show which tool was upgraded.

My first question is, what is the best way to pass the tool information into the order?

My thinking is that I need a custom text attribute in the product that passes on into the order when the product is ordered.

I'm not sure if this is the best route, but I think a way to do it is by adding the "WooCommerce Product Addons" plugin.
https://wordpress.org/plugins/woocommerce-product-addon/
This solves the custom attribute side of things. The product now has a field attached to it that can accept a text entry. The text is passed into the cart and on to the order.

So I now need to get the CRED form to pass the Tool title into the product attribute when the Tool is added to the cart.

I think maybe I can use cred_commerce_add_product_to_cart, but not sure how I get this to add the attribute when the product is added to the cart.

If there's a better way to do what I'm attempting please let me know.

Thanks
Tim

#919231

Dear Tim,

There isn't such a built-in feature within, but you try with some custom PHP codes, for example, when user submit the Toolset form, user is redirected to Woocommerce cart page, it will trigger action hook "cred_commerce_after_add_to_cart", for example setup a global PHP variable value as the post ID, in the Wocoomerce cart page, get the global var value, and display it's post title
https://developer.wordpress.org/reference/functions/get_the_title/.

more help
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_add_to_cart
hidden link

I think it is the simplest way