0.00  View cart

Support Easy Booking: Duration Discounts [Resolved] Set maximum price for product

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8043
    Christoph
    Participant

    Hi Natasha,

    is there a way to include a check if the booking price exceeds a certain amount and set this price instead to a maximum price?

    E.g. the maximum price for a product is 50€, so any amount above is not facturated. This is highly important for bookable bundle products as no customer wants to pay more rent for an additional option than the buy price would be.

    Yes, it is possible to add seperate fixed duration discount lines for each day through the duration discounts. But that leads to many duration discount lines as I have to create lines like “11 to 11 nights: -5€”, “12 to 12 nights: -10€”, “13 to 13 nights: -15€” and so on, so it is not very practicable for many products.

    Thank you in advance!

    Best regards,

    Christoph

    #8046
    Ashanna
    Plugin's author

    Hello,

    Please try to add this code to your theme’s functions.php:

    add_filter( 'easy_booking_new_price', 'wceb_set_maximum_booking_price', 99, 4 );
    add_filter( 'easy_booking_new_regular_price', 'wceb_set_maximum_booking_price', 99, 4 );
    
    function wceb_set_maximum_booking_price( $price, $data, $product, $_product ) {
    
        if ( $price > 50 ) {
            $price = wc_format_decimal( 50 );
        }
    
        return $price;
    
    }

    You have access to the $product (product) and $_product (variation or child product if there is one) variables if you need to apply this to some products only 🙂

    I hope this helps. Tell me if you need more help to customize the code.

    Regards,
    Natasha

    #8048
    Christoph
    Participant

    Hi Natasha,

    thanks a lot, that works fantastic for bundles and single products! You should add that to your documentation, I think it is a helpful piece of code.

    I customized it a little bit, here is my code if anyone is interested:

    add_filter( 'easy_booking_new_price', 'wceb_set_maximum_booking_price', 99, 4 );
    add_filter( 'easy_booking_new_regular_price', 'wceb_set_maximum_booking_price', 99, 4 );
    
    function wceb_set_maximum_booking_price( $price, $data, $product, $_product ) {
    	$childProductId = $_product->get_id();
    	
    	$max50EurosProducts = array(51687, 51428, 47201, 43500); 
    	$max100EurosProducts = array(47216);
    	
    	if (in_array($childProductId, $max50EurosProducts))	{
    		if ( $price > 50 ) {
    			$price = wc_format_decimal( 50 );
    		}
    	}
    	
    	if (in_array($childProductId, $max100EurosProducts) )	{
    		if ( $price > 100 ) {
    			$price = wc_format_decimal( 100 );
    		}
    	}
    
        return $price;
    
    }

    Best regards,

    Christoph

    #8049
    Ashanna
    Plugin's author

    Perfect 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘[Resolved] Set maximum price for product’ is closed to new replies.

Want to know what's next with Easy Booking? Check the roadmap!