Documentation

Add these snippets to your child theme’s functions.php file or use a plugin like Code snippets. Don’t add code directly to the parent theme’s functions.php file as it will be overridden by updates. Customize the texts/values in red to whatever you need.

Remove price calculation

add_filter( 'easy_booking_calculate_booking_price', '__return_false' );

Remove price calculation for some products only

add_filter( 'easy_booking_calculate_booking_price', 'wceb_calculate_booking_price', 10, 2 );

function wceb_calculate_booking_price( $calc, $_product ) {

    if ( $_product->get_id() == 'ID' ) {
        $calc = true; // Set true to enable price calculation, or false to disable.
    }

    return $calc;

}

Early bird pricing

Example for a 5% discount if booked at least 10 days before start date.

add_filter( 'easy_booking_one_date_price', 'wceb_early_bird_pricing', 40, 5 );
add_filter( 'easy_booking_two_dates_price', 'wceb_early_bird_pricing', 40, 5 );

function wceb_early_bird_pricing( $new_price, $product, $_product, $booking_data, $price_type ) {

    $current_date = time();
    $start_date = strtotime( $booking_data['start'] );

    // Get interval between current date and start date
    $interval = (int) ( $start_date - $current_date ) / 86400;

    if ( $interval >= 10 ) {
        $new_price *= 0.95;
    }

    return $new_price;

}

Bulk add product prices

Example to set Saturday and Sunday price to 0 for all products. Add the code, save Easy Booking settings, then remove the code.

function set_weekend_prices() {

    $prices = array(

        array(
            'type'        => 'day', // day, date or daterange
            'date_from'   => '6', // Int from 1 to 7 or yyyy-mm-dd
            'date_to'     => null, // null or yyyy-mm-dd
            'price'       => '0',
            'sale_price'  => null,
            'unit'        => 'single', // single or mutli
            'repeat'      => 'no' // yes or no
        ),
        array(
            'type'        => 'day',
            'date_from'   => '7',
            'date_to'     => null,
            'price'       => '0',
            'sale_price'  => null,
            'unit'        => 'single',
            'repeat'      => 'no'
        )

    );

    $args = array(
        'post_type'      => array( 'product', 'product_variation' ),
        'posts_per_page' => -1,
        'post_status'    => 'publish'
    );

    $query = new WP_Query( $args );

    while ( $query->have_posts() ) : $query->the_post();
        global $post;
        wceb_save_product_prices( $post->ID, $prices );
    endwhile;
}

add_action( 'easy_booking_save_settings', 'set_weekend_prices' );