function - WooCommerce override woocommerce_cart_product_price -


i override following code in child theme functions.php file. because want product_price show "get_price_including_tax" instead of excluding, rest of cart should remain excluding taxes.

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 ); } 

need switch "get_price_including_tax()" , "get_price_excluding_tax()", seems trick, don't want edit core files.

tried this:

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 ); } 

which gives me following error (url removed in error):

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 

if remove $this-> code, following error:

fatal error: call 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 

can me in proper direction please? i'm no programmer unfortunately, have no idea i'm doing.

many thanks!

don't know if solved or not, first error listed:

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 

tells $this doesn't refer anything. kind of need backtrack figure out $this should mean. try changing line:

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

to this:

if ( $woocommerce->cart->tax_display_cart == 'excl' ) { 

you may need call global $woocommerce before so:

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

that should @ least past first error , can see if things work there.


Comments