在WooCommerce中获取日期范围内的可预订产品的价格数据 [英] Get pricing data for a bookable product with date ranges in WooCommerce
问题描述
我想根据日期范围向客户显示价格.
I would like to show to customers the price according to a date range.
在具有日期范围定价的可预订产品中,我有:
In on of my bookable product with date rage pricing I have:
- 基本价格:第一天为100美元,
- 在两天内(在日期范围内)将基本价格增加$ 60,
- 在三天之内(在日期范围内)向底价加价90美元.
依此类推...
这是在woocommerce可预订产品编辑设置页面的后端完成的.
This is done in the backend of the woocommerce bookable product edit settings page.
现在的问题是,我无法在数据库中的任何位置找到这些添加项(60、90).使用:
My problem is now, that I cannot find those additions (60, 90) anywhere in the database. With:
$product = wc_get_product( $product_id );
$price = $product->get_price();
它仅返回基本价格(100 $).
It only return the base price (100$).
对于在数据库中某个地方找到这些日期范围设置或woocommerce将根据默认值计算该日期范围设置的任何帮助,都将受到赞赏.
Any help in finding those date range settings somewhere in the database or where woocommerce would calculate this per default is appreciated.
推荐答案
对于WooCommerce预订,您具有WC_Product_Booking
对象中所需的所有内容:
For WooCommerce Bookings you have everything needed in the WC_Product_Booking
object:
// Get an instance of the WC_Product object (Here a WC_Product_Booking object)
$product = wc_get_product( $product_id );
// Get the base price
$base_price = $product->get_price();
// Get all related protected data in an array
$product_data = $product->get_data();
// Get the additional pricing data for this bookable product (array)
$product_pricing = $product_data['pricing'];
// iterating through each pricing row
foreach($product_pricing as $key => $princing ){
$pricing_type = $princing['type'];
$pricing_base_cost = $princing['base_cost']; // <= this is the price you are looking for
$pricing_base_modifier = $princing['base_modifier'];
$pricing_cost = $princing['cost'];
$pricing_modifier = $princing['modifier'];
$pricing_from = $princing['from'];
$pricing_to = $princing['to'];
}
// Raw pricing data output (for tests)
echo '<pre>'; print_r($product_pricing); echo '</pre>';
现在在数据库中,您可以在_wc_booking_pricing
meta_key
下的wp_post_meta
表中找到此数据...因此,您也可以从产品ID中通过以下方式访问它:
Now in the database you can find this data in wp_post_meta
table under _wc_booking_pricing
meta_key
… So from the product ID you can access it too with:
$pricing_data = get_post_meta( $product_id, '_wc_booking_pricing', false);
// Raw pricing data output (for tests)
echo '<pre>'; print_r($product_pricing); echo '</pre>';
这篇关于在WooCommerce中获取日期范围内的可预订产品的价格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!