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

时间:2017-11-21 11:22:08

标签: php wordpress woocommerce product price

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

我想不包括本网站的每小时价格。所以我尝试谷歌并检查没有选项禁用租赁产品的每小时价格。

我已经检查了插件代码,如果有什么我可以做的,并且看到了这个:

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 的预订和租借系统插件源代码中。

我想知道是否有人之前已经处理过这个问题,或者任何自定义都可以。我试过但似乎没有任何工作,我的意思是它不会禁用该功能。

我的情景

在网站上,当客户选择日期时,例如从2017年11月20日到2017年11月20日,然后按照给定的插件计算小时价格(在仪表板中精确计算)每小时价格如果预订或租赁天数为1天,将适用。但是从2017年11月20日到2017年11月22日这个日期范围是合适的。所以我只想启用日期租赁价格。

1 个答案:

答案 0 :(得分:2)

最后我能够解决它并且花了一段时间,因为我之前习惯使用'PHP'。以下是我用来禁用每小时价格功能的步骤:

首先让我写一下,我几乎不可能从WordPress信息中心禁用该功能。如果有人可以,请告诉我。所以我做了什么,我开始定制插件代码,这里是插件的链接 - WooCommerce Rental and Booking Plugin

首先打开 wp-content 文件夹中的 class-redq-product-cart.php 文件,这里是文件路径 - wp-content \插件\预订和租赁系统用woocommerce \包括即可。我在第x行的函数 redq_rental_get_item_data()中更改了一些代码。 98(我使用Dev PHP)如下:

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

在同一个文件中,第x行还有另一个名为 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的前端。在前端,您必须立即反映每日租金的定价,例如:

Sample Front-End Image

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

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

它运作的方案 - 我再次写信,当您在同一日期范围内有任何租借时,此功能正常运行。假设,从2017年11月22日到2017年11月22日。如果它是按小时价格和同一天写的,这是好的。默认情况下,在仪表板中,对于此日期范围,WooCommerce计算每小时价格并强制禁用此功能,您必须完成代码隐藏。