使用预订和租赁系统插件在 WooCommerce 中禁用每小时价格

Disable Hourly Price in WooCommerce with Booking and rental system plugin

我有一个使用 WooCommerce 和 Booking and rental system 插件的租赁网站。

我不想在本网站中包含小时价格。所以我尝试 google 并检查没有选项可以禁用租赁产品的小时价格。

如果我能做任何事情,我已经检查了插件代码并看到了这个:

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' => ''
        ;
    }
}

includes\class-redq-product-cart.php 的预订和租赁系统插件源代码中。

我想知道是否有人以前处理过这个问题或者可以进行任何定制。我试过了,但似乎没有任何效果我的意思是它不会禁用该功能。

我的场景

在网站上,当客户选择日期时,例如从 20/11/2017 到 20/11/2017,然后它会按照给定的插件(准确地在仪表板中)计算每小时价格 如果预订或租赁天数最少 1 天,则按小时收费。但是当日期范围是从 20/11/2017 到 22/11/2017 时,一般价格就可以正常工作。所以我只想启用日期租赁价格。

最后我解决了这个问题,这花了我一段时间,因为我之前习惯于使用 'PHP'。所以这是我用来禁用每小时价格功能的步骤:

首先让我写一下,我几乎不可能从 WordPress 仪表板禁用该功能。如果有人可以,请告诉我。所以我做了什么,我开始自定义插件代码,这里是插件的 link - WooCommerce Rental and Booking Plugin

首先打开 class-redq-product-cart.php 文件,它位于 wp-content文件夹,这里是文件路径 - wp-content\plugins\booking-and-rental-system-woocommerce\includes。我在函数 redq_rental_get_item_data() 的第 1 行更改了一些代码。 98(我用的是DevPHP)如下:

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' => ''
        );
    }

在同一个文件中,第 1 行还有另一个名为 redq_rental_order_item_meta() 的方法。 175 请注意,本节计算的是天数和小时数。为了强制不计算小时价格,我将之前的代码替换为以下代码:

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

以上是使用PHP完成后端部分,现在使用jQuery完成前端。在前端,您必须立即反映每日租金的定价,例如:

为此,您必须打开一个名为 cost-handle.js 的文件,文件路径为 wp-content\plugins\booking-and-rental-system-woocommerce\assets\js.只需将第 55 行的代码替换为以下代码,并记住这是一个 JavaScript 文件(如果您希望在 PHP 文件中查看定义的文件名,请参见第 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');                             
}

我希望,这将帮助其他人解决问题,并尽力解决并理解。

它起作用的场景 - 我再次写信,当您在同一日期范围内有任何要出租的东西时,它就起作用了。假设,从 22/11/2017 到 22/11/2017。如果它是按小时计价且写入日期相同,这很好。默认情况下,在仪表板中,对于此日期范围,WooCommerce 计为每小时价格,要强制禁用它,您必须通过代码隐藏。