Support

Account

Home Forums General Issues WooCommerce Cart and custom field

Helping

WooCommerce Cart and custom field

  • Hi,

    I have set up one custom field (text) for WooCommerce products.
    I’m able to show it’s content on product page, but I also want to show the content of that field in cart under product title.

    <td class="product-name">
    						<?php
    							if ( ! $_product->is_visible() ) {
    								echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . '&nbsp;';
    							} else {
    								echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s </a>', esc_url( $_product->get_permalink( $cart_item ) ), $_product->get_title() ), $cart_item, $cart_item_key);
    							}
    							// Meta data
    							echo WC()->cart->get_item_data( $cart_item );
    							// Backorder notification
    							if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
    								echo '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'rebuild' ) . '
    ';
    							}
    						?>
    <?php the_field('areas'); ?>
    					</td>

    I understand that the custom field code need to know for which product show it’s content. How to get value of that field for the product in cart?

  • Hi @artur

    You need to provide the product ID as the second parameter of the the_field() or get_field() functions. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_field/. So, you should be able to do it like this:

    the_field('areas', $_product->id);

    I hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘WooCommerce Cart and custom field’ is closed to new replies.