我想要显示折扣价格(添加范围后的价格)以及可预订产品的基本价格。我要做的是更改\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>';这是正确的方法吗?或者你能提出一些建议吗?
发布于 2020-09-22 06:46:13
覆盖Woocommerce Bookings的核心代码是你绝对不应该做的事情,因为有很多不同的原因,我不打算解释。
现在,正如您在源代码中看到的那样,开发人员添加了一个过滤器挂钩,允许您对$output变量进行更改。
现在在WooCommerce bookable产品中没有任何折扣价格,就像在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文件中。
https://stackoverflow.com/questions/63983457
复制相似问题