[英]Show discounted price in Woocommerce Bookings
我想顯示折扣價(添加范圍后的價格)以及可預訂產品的基本價格我正在做的是更改 \woocommerce-bookings\includes\adminclass-wc-bookings-ajax.php 中的以下代碼文件
// Build the output
$before = $product->get_price();
$after = wc_price( $display_price ) ;
$discount = $product->get_price() - wc_price( $display_price );
$output = apply_filters( 'woocommerce_bookings_booking_cost_string', __( 'Booking cost', 'woocommerce-bookings' ), $product ) .$discount ': <strong>' .$discount . $price_suffix . '</strong>';
這是正確的方法還是你能提出什么建議?
重寫 Woocommerce Bookings 核心代碼是你絕對不應該做的事情,原因有很多,我不打算解釋。
現在您可以在該源代碼中看到,開發人員添加了一個過濾器掛鈎以允許您對$output
變量進行更改。
現在 WooCommerce 可預訂產品與 WooCommerce 其他產品一樣沒有任何折扣。
所以首先放回原來的插件文件。
然后您可以按如下方式使用過濾器(您將在其中添加自己的代碼):
add_filter( 'woocommerce_bookings_booking_cost_string', 'change_bookings_booking_cost_string', 10, 2 );
function change_bookings_booking_cost_string( $cost_string, $product ) {
$raw_price = $product->get_price();
$display_price = wc_get_price_to_display($product);
$price_suffix = $product->get_price_suffix();
$formatted_price = wc_price($display_price) . $price_suffix;
$additional_output = 'Here comes your code'; // Replace by your code variables
return $cost_string . ' ' . $additional_output; // Always return (never echo)
}
代碼進入您的活動子主題(或活動主題)的 functions.php 文件。
您能否指出我如何做到這一點,以便每個可預訂產品根據每種產品顯示折扣價?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.