0
votes

I am working on a restaurant website based on Woocommerce - the client has different prices for his products - one price for delivery, and one price for sitting.

The customer can order products and be delivered and also he can book a table in the restaurant, by ordering the products, and in the checkout section he selects the book a table option.

So - am I able to have 2 prices for a product and then apply one of them depending on the delivery method?

Variations is not a good idea - since I cannot have one product for sitting and one for table booking in the cart.

1
The simplest method would be to make "Delivery Method" an attribute of the product. And attributes CAN change the price of the product. - random_user_name
Yes, but i don't want the users to be able to select products from delivery and booking - it would mess the entire flow. - Alex Bohariuc
In this case, why not use "Shipping" methods? - random_user_name
Can you be more specific please? - Alex Bohariuc
I guess you could add a field to the metabox for "delivery" price. And use the default price as the "dine in" price. (Or vice versa). You'd be able to display this additional field in the template somewhere. And then when you set the delivery method (perhaps as a shipping method) you can alter the cart prices. - helgatheviking

1 Answers

0
votes

check below code, it may give you idea about fulfill your requirement.

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
    function add_custom_price( $cart_object ) {   
        foreach ( $cart_object->cart_contents as $key => $value ) {   
            $productId = $value['data']->id;
            if ( check delivered product) {
            {
                // product to be delivered              
                $value['data']->price = $value['data']->price + $your_custom_price;
            }
            else{
                //book table
                $value['data']->price = $value['data']->price;
            }
        }
    }
    }