Answer the question
In order to leave comments, you need to log in
How can I display text after the price of products of a certain category in the woocommerce cart without affecting the final price?
Good day to all. I ran into one issue while studying woocommerce. I'm making a small shop that will have beer and snacks. There are 2 categories of beer & snack products. The question is actually what. How can I display text in the cart after the price of goods of a certain category without affecting the final price. Let's say after the price for beer indicate that this is the price per liter. And in the price for a snack, indicate what it is for 50 grams. A photo is attached to make my question clearer. And another small question: how can I add the unit of measurement in the input in the basket to the quantity of the beer category (l.) and to the quantity of the snack category (gr.)?
Answer the question
In order to leave comments, you need to log in
I don’t know how you store units, so I’ll assume that the meta field is _product_units , then we do this.
function wpp_add_units_after_price_in_cart( $price, $cart_item, $cart_item_key ) {
// если единицы измерения хранятся не в в мета поле _product_units, тут получаем их
// из места их хранения по своему
$units = get_post_meta( $cart_item['product_id'], '_product_units', true );
if ( ! empty( $units ) ) {
$price .= ' ' . $units ;
}
return $price;
}
add_filter( 'woocommerce_cart_item_price', 'wpp_add_units_after_price_in_cart', 10, 3 );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question