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 );