Uncaught Error: Call to a member function get_price()
-
Hello there,
We have a custom snippet on our site to format prices with and without taxes and whenever we enable that snippet, your search plugin throws the following fatal error.
Fatal error: Uncaught Error: Call to a member function get_price() on null in /home/customer/www/abcd.com/public_html/wp-content/plugins/woocommerce/includes/wc-product-functions.php:1047 Stack trace: #0 /home/customer/www/abcd.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code(6): wc_get_price_excluding_tax(NULL) #1 /home/customer/www/abcd.com/public_html/wp-includes/class-wp-hook.php(287): pm_price_formatting('<span class="wo...', NULL) #2 /home/customer/www/abcd.com/public_html/wp-includes/plugin.php(212): WP_Hook->apply_filters('<span class="wo...', Array) #3 /home/customer/www/abcd.com/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(1803): apply_filters('woocommerce_get...', '<span class="wo...', Object(WC_Product_Simple)) #4 /home/customer/www/abcd.com/public_html/wp-content/plugins/advanced-woo-search/includes/class-aws-search.php(572): WC_Product->get_price_html() #5 /home/custom in /home/customer/www/abcd.com/public_html/wp-content/plugins/woocommerce/includes/wc-product-functions.php on line 1047
Here’s the custom snippet:
add_filter( 'woocommerce_get_price_html', 'pm_price_formatting', 99, 2 ); function pm_price_formatting ( $price, $product ){ global $product; $currency = esc_attr( get_woocommerce_currency( ) ); // Get the currency code. $price_excl_tax = number_format (wc_get_price_excluding_tax( $product ), 2); // price without VAT $price_incl_tax = number_format (wc_get_price_including_tax( $product ), 2); // price with VAT $int = wc_get_price_decimals(); $price = '<span class="price-without-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) .$price_excl_tax.' (Exc. VAT)'.'</span>'.' | '.'<span class="price-with-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) . $price_incl_tax.' (Inc. VAT)'.'</span>'; return $price; }
Could you please let us know how to get this issue rectified?
Many thanks in advance
- The topic ‘Uncaught Error: Call to a member function get_price()’ is closed to new replies.