Hello I have tried checking the issue and i couldn’t solve it.
I used this code in my function.php
//change price output label
function cw_change_product_price_display( $price ) {
$sell_price = get_field('sell_price', $product_id);
$sell_duration = get_field('duration', $product_id);
$price .= " | SELL ₦$sell_price in $sell_duration";
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
And it’s working perfectly in the product page. Is there a way i could output this?
I also saw this solution but i din’t get the explantion. https://support.advancedcustomfields.com/forums/topic/add-custom-fields-to-woocommerce-cart
Any assistance will be appreciated. Thanks.
$product_id
has no value in your code
function cw_change_product_price_display( $price, $product ) {
$sell_price = get_field('sell_price', $product->ID);
$sell_duration = get_field('duration', $product->ID);
$price .= " | SELL ₦$sell_price in $sell_duration";
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' 10, 2);
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' 10, 2);
The answer above was so close; the key to my success was $cart_item
:
function price_count_cart( $price_cart, $cart_item, $cart_item_key ) {
$product_id = $cart_item['product_id'];
$count_cart = get_field('count', $product_id);
if (!$count_cart) {
return $price_cart;
}
else {
return '<span class="custom-prc">'.$price_cart.' / <small>'.$count_cart.'</small></span>';
}
}
add_filter( 'woocommerce_cart_item_price', 'price_count_cart', 10, 3 );