Support

Account

Home Forums Front-end Issues Display field in woocommerce cart

Unread

Display field in woocommerce cart

  • I’ve got a custom field in my products’ page – which is a Relationship field to custom post type – and I’d like to display a field of my custom post type for every product in my cart page.

    More specifically: I have a product associated with a brand (CPT). The brand has a ‘shipping time’ field that I’d like to display for every product associated to it.

    At the moment my function is partially working, in the sense that it displays the request value, but ONLY for the first item in the cart. That’s my code in function.php

    add_filter( 'woocommerce_get_item_data', 'wc_add_shipping_to_cart', 10, 2 );
    function wc_add_shipping_to_cart( $cart_item_data, $cart_item ) 
    { 
        if( $brand_select = get_post_meta( $cart_item['product_id'], 'brand_select', true ) ) {
            if( $shipping_time = get_field('shipping_time_brand', $brand_select ) ) {
                $cart_item_data[] = array(
                    'name'      => __( 'Shipping', 'woocommerce' ),
                    'value'     => $shipping_time,
                );
            }
        }
        return $cart_item_data;
    }
    

    Do you know maybe why that’s not working properly?

Viewing 1 post (of 1 total)

The topic ‘Display field in woocommerce cart’ is closed to new replies.