【发布时间】:2016-07-14 07:02:48
【问题描述】:
我想在我的子主题functions.php 文件中覆盖以下代码。因为我希望 product_price 显示“get_price_included_tax”而不是排除,但购物车的其余部分应保持不含税。
public function get_product_price( $_product ) {
if ( $this->tax_display_cart == 'excl' ) {
$product_price = $_product->get_price_excluding_tax();
} else {
$product_price = $_product->get_price_including_tax();
}
return apply_filters( 'woocommerce_cart_product_price', wc_price( $product_price ), $_product );
}
需要切换“get_price_including_tax()”和“get_price_ exclude_tax()”,这似乎可以解决问题,但我不想编辑核心文件。
试过这个:
add_filter('woocommerce_cart_product_price', 'product_price_incl_tax');
function product_price_incl_tax($_product ) {
if ( $this->tax_display_cart == 'excl' ) {
$product_price = $_product->get_price_including_tax();
} else {
$product_price = $_product->get_price_excluding_tax();
}
return apply_filters( 'product_price_incl_tax', wc_price( $product_price ), $_product );
}
这给了我以下错误(错误删除了网址):
Fatal error: Using $this when not in object context in /public/sites/www.t-instyle.nl/paperbag/wp-content/themes/virtue_child/functions.php on line 7
如果我从代码中删除 $this->,我会收到以下错误:
Fatal error: Call to a member function get_price_excluding_tax() on string in /public/sites/www.t-instyle.nl/paperbag/wp-content/themes/virtue_child/functions.php on line 10
谁能帮助我正确的方向?不幸的是,我不是程序员,所以我基本上不知道自己在做什么。
非常感谢!
【问题讨论】:
-
你有解决办法吗?
标签: function filter woocommerce hook cart