Home › Forums › ACF PRO › Show ACF Value in Wocommerce Cart Total Area › Reply To: Show ACF Value in Wocommerce Cart Total Area
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;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.