Support

Account

Home Forums Front-end Issues Display field in woocommerce cart

Unread

Display field in woocommerce cart

    • vigotso

    • December 4, 2018 at 4:47 am

    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)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.