Search code examples
phpwordpresswoocommerceproduct

Disable Hourly Price in WooCommerce with Booking and rental system plugin


I have a rental website using WooCommerce and Booking and rental system plugins.

I would like to Not include hourly prices in this website. So I tried to google and checked there are no option to disable the hourly prices for rental products.

I've checked the plugin code if anything I can do and seen this:

if(isset($rental_data['rental_days_and_costs'])){
    if($rental_data['rental_days_and_costs']['days'] > 0){
      $custom_data[] = array(
            'name'    => 'Total Days',
            'value'   => $rental_data['rental_days_and_costs']['days'],
                        'display' => ''
                    );
    } else {
      $custom_data[] = array(
            'name'    => 'Total Hours',
            'value'   => $rental_data['rental_days_and_costs']['hours'],
                        'display' => ''
        ;
    }
}

in the Booking and rental system plugin source code at includes\class-redq-product-cart.php.

I would like to know if anyone has dealt this before or any customization is possible. I tried but nothing seems to be working I mean it doesn't disable the feature.

My Scenario:

In the website, when a customer selects the date, like from 20/11/2017 and to 20/11/2017, then it counts hourly price as in the plugin given (In the dashboard precisely) Hourly price will be applicable if booking or rental days min 1day. But works fine for the general price when the date range is like this from 20/11/2017 and to 22/11/2017. So I just want to enable the date-wise rental price.


Solution

  • Finally I was able to solve it and it took a while as I was used to work with 'PHP' earlier. So here are the steps that I used to disable the hourly price feature:

    Firstly let me write it is almost impossible for me to disable the feature from the WordPress dashboard. If anyone can, let me know. So what I did, I started to customize the plugin code and here is the link of the plugin - WooCommerce Rental and Booking Plugin

    First open the class-redq-product-cart.php file that's inside the wp-content folder and here is the file path - wp-content\plugins\booking-and-rental-system-woocommerce\includes. I changed a bit of code in the function redq_rental_get_item_data() at line no. 98 (I use Dev PHP) as the following:

    if(isset($rental_data['rental_days_and_costs'])){
       if($rental_data['rental_days_and_costs']['days'] > 0) {
            $custom_data[] = array(
              'name'    => 'Total Days',
              'value'   => $rental_data['rental_days_and_costs']['days'],
              'display' => ''
            );
        } else {
            $custom_data[] = array( //Initially you'll have hourly rent details here - Just replace with this for per day rental
               'name'    => 'Total Days',
               'value'   => 1,
              'display' => ''
            );
        }
    

    In the same file, there is another method named redq_rental_order_item_meta() at line no. 175 and be careful, in this section days and hours are calculated. To force not to count the hourly price, I replace the earlier code with the following:

    if($hours < 24) {
        $days = 1; //Initially this would be $days = 0 and replace it
        $total_hours = ceil($days);
    } 
    

    The above is done for the back-end part using PHP and now come for the front-end with jQuery. In the front-end, you have to reflect the pricing instantly for the per day rental as an example something like this:

    Sample Front-End Image

    For this, you have to open a file called cost-handle.js and the file path is wp-content\plugins\booking-and-rental-system-woocommerce\assets\js. Just replace the code with the following at line no 55 and remember this is a JavaScript file (If you wish to see the defined file name in the PHP file, see this at line no. 234 - wp-content\plugins\booking-and-rental-system-woocommerce\redq-rental-and-bookings.php):

    if(hours < 24) {
        days = 1; //make the day 1 and initailly it's defined 0
        total_hours = Math.ceil(hours);
    
        $('.additional_person_info').trigger("chosen:updated");
    
        $('.show_person_cost_if_day').hide();
        $('.show_person_cost_if_time').show();
    
        //$('.show_if_day').children('.amount').css({'visibility': 'hidden'});
        $('.show_if_day').children('span').hide();
        $('.show_if_time').show();
    
        $('.rnb_single_add_to_cart_button').removeAttr('disabled','disabled');                             
    }
    

    I hope, this will help others to solve the issue and tried my best to solve and make understand.

    The scenario that it worked - I am writing again, this works when you have anything for rental within the same date range. Suppose, from 22/11/2017 and to 22/11/2017. This is fine if it's for hourly price and for the same date written. By default, in the dashboard, for this date range, WooCommerce counts for hourly price and to forcefully disable this, you have to go through code-behind.