Support

Account

Forum Replies Created

  • Here is the action and filter I’m using to show on product page and the cart:

    function save_my_custom_product_field( $cart_item_data, $product_id ) {
    
        $custom_field_value = get_field( 'install_fee', $product_id, true );
    
        if( !empty( $custom_field_value ) ) 
        {
            $cart_item_data['install_fee'] = $custom_field_value;
    
            // below statement make sure every add to cart action as unique line item
            $cart_item_data['unique_key'] = md5( microtime().rand() );
        }
        return $cart_item_data;
    }
    
    add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart', 10, 2 );
    
    function render_meta_on_cart( $cart_data, $cart_item ) {
        $custom_items = array();
        // Woo 2.4.2 updates
        if( !empty( $cart_data ) ) {
            $custom_items = $cart_data;
        }
        if( isset( $cart_item['install_fee'] ) ) {
            $custom_items[] = array( "name" => "Install Fee $", "value" => $cart_item['install_fee'] );
        }
        return $custom_items;
    }
    
Viewing 1 post (of 1 total)