我有一个使用 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
。
我想知道是否有人以前处理过这个问题或者可以进行任何定制。我尝试过,但似乎没有任何效果,我的意思是它不会禁用该功能。
我的场景:
在网站中,当客户选择日期(例如从 20/11/2017 到 20/11/2017)时,它会按照给定的插件计算每小时价格(精确地在仪表板中)每小时价格如果预订或租赁天数至少为 1 天,则适用。但当日期范围是从 20/11/2017 到 22/11/2017 时,对于一般价格来说效果很好。所以我只想启用按日期排列的租金价格。
最佳答案
最后我能够解决这个问题,并且花了一段时间,因为我之前习惯使用“PHP”。以下是我用来禁用每小时价格功能的步骤:
首先让我写一下,我几乎不可能从 WordPress
仪表板禁用该功能。如果有人可以,请告诉我。所以我做了什么,我开始自定义插件代码,这是插件的链接 - WooCommerce Rental and Booking Plugin
首先打开 wp-content 文件夹中的 class-redq-product-cart.php 文件,这里是文件路径 - wp-content\plugins\booking-and-rental-system-woocommerce\includes。我在函数 redq_rental_get_item_data() 的第 1 行更改了一些代码。 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' => ''
);
}
在同一个文件中,第 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
为前端部分完成。在前端,您必须立即反射(reflect)每日租金的定价,例如如下所示:
为此,您必须打开一个名为 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
计算每小时价格,要强制禁用此功能,您必须执行代码隐藏。
关于php - 使用预订和租赁系统插件禁用 WooCommerce 中的每小时价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47411881/