Home › Forums › General Issues › Add Custom Fields to Woocommerce Cart › Reply To: Add Custom Fields to Woocommerce Cart
Got it figured out!
I stumbled across your code snippet for drawing a field from another page and all logic told me that should work. So I fumbled around with it for a bit until I got it to work. It wouldn’t pull in the post ID, but I noticed Woocommerce uses $product_id. When I replaced the page id location with $product_id, voila! It worked!
Here’s a sample for anyone else that needs to figure this out.
<?php the_field('your-field-name', $product_id ); ?>
Also, using $product_id worked for drawing in my custom taxonomy too.
The Checkout page also needed some customizing and I found I needed to do one extra step. The snippet of code that creates the $product_id variable is missing on checkout.php. I grabbed it from cart.php and everything worked fine. Below is the code snippet you need to add to checkout to use the $product_id variable.
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.