Support

Account

Home Forums ACF PRO Show ACF Value in Wocommerce Cart Total Area

Helping

Show ACF Value in Wocommerce Cart Total Area

  • I’ve got an ACF value called install_fee for my items. I can pull the value fine in the product page and with filters and hooks can get it to show up on the cart under the items. I don’t want this value added into the totals until after the tax has been calculated.

    I’m trying to get it to hook into the cart-totals.php page that shows the tax then totals.

    I’ve got the holder for it showing but can’t seem to figure out the hook to pull it into the cart totals so that it can be displayed after the tax and then added to the final cart total.

    Looking for some guidance towards the right direct or hook.

  • 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 2 posts - 1 through 2 (of 2 total)

The topic ‘Show ACF Value in Wocommerce Cart Total Area’ is closed to new replies.