M
M
MaximYurin2017-02-12 01:40:08
PHP
MaximYurin, 2017-02-12 01:40:08

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.)?b6b8e83e6f574a69809c82ba6df5cf28.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2017-02-12
@MaximYurin

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 );

M
Max Lomov, 2017-02-12
@theLomov

As far as I remember, in the settings there seem to be units of measurement in the settings of woocommerce itself (I won’t send it in the exact direction, because I haven’t encountered the admin panel for a long time).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question