Function WooCommerce覆盖WooCommerce\u购物车\u产品\u价格

Function WooCommerce覆盖WooCommerce\u购物车\u产品\u价格,function,filter,woocommerce,hook,cart,Function,Filter,Woocommerce,Hook,Cart,我想重写我的child-theme-functions.php文件中的以下代码。因为我希望产品价格显示“get_price_include_tax”,而不是Exclude,但购物车的其余部分应保持不含税 public function get_product_price( $_product ) { if ( $this->tax_display_cart == 'excl' ) { $product_price = $_product->get_price_excluding_ta

我想重写我的child-theme-functions.php文件中的以下代码。因为我希望产品价格显示“get_price_include_tax”,而不是Exclude,但购物车的其余部分应保持不含税

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_include_tax()”和“get_price_include_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 );
}
这给了我以下错误(url错误删除):

如果从代码中删除$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
有人能帮我找到正确的方向吗?不幸的是,我不是程序员,所以我基本上不知道自己在做什么


非常感谢

不知道您是否已经解决了此问题,但您列出的第一个错误是:

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
不引用任何内容。所以你需要回溯一下,弄清楚这是什么意思。尝试更改此行:

if ( $this->tax_display_cart == 'excl' ) {
为此:

if ( $woocommerce->cart->tax_display_cart == 'excl' ) {
在此之前,您可能还需要调用全局
$woocommerce
,以便:

function product_price_incl_tax($_product ) {
global $woocommerce;
if ( $woocommerce->cart->tax_display_cart == 'excl' ) {

这至少可以让您克服第一个错误,然后您就可以看到是否从那里开始工作。

不知道您是否已经解决了这个问题,但您列出的第一个错误是:

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
不引用任何内容。所以你需要回溯一下,弄清楚这是什么意思。尝试更改此行:

if ( $this->tax_display_cart == 'excl' ) {
为此:

if ( $woocommerce->cart->tax_display_cart == 'excl' ) {
在此之前,您可能还需要调用全局
$woocommerce
,以便:

function product_price_incl_tax($_product ) {
global $woocommerce;
if ( $woocommerce->cart->tax_display_cart == 'excl' ) {

这至少可以让您通过第一个错误,然后您就可以看到是否从那里开始工作。

您有解决方案吗?您有解决方案吗?