Fatal error when using WooCommerce shortcode
-
Hello!
I have an issue with Yoast on my install.
I use the following code in my functions.php to display the SKU of a product in a shortcode in the product description:
function display_woo_sku() { global $product; return $product->get_sku(); } add_shortcode( 'woo_sku', 'display_woo_sku' );I have no problems with this code at all, but as soon as I activate Yoast, I get a fatal error whenever i update or publish a product containing the shortcode.
I get the following error:
Fatal error: Uncaught Error: Call to a member function get_sku() on null in /wp-content/themes/shopkeeper-child/functions.php:14 Stack trace: #0 /wp-includes/shortcodes.php(319): display_woo_sku('', '', 'woo_sku') #1 [internal function]: do_shortcode_tag(Array) #2 /wp-includes/shortcodes.php(197): preg_replace_callback('/\\[(\\[?)(woo_sk...', 'do_shortcode_ta...', '<p>[vc_row full...') #3 /wp-includes/class-wp-hook.php(286): do_shortcode('<p>[vc_row full...') #4 /wp-includes/plugin.php(203): WP_Hook->apply_filters('<p>[vc_row full...', Array) #5 /wp-content/plugins/wordpress-seo/admin/links/class-link-watcher.php(114): apply_filters('the_content', '[vc_row full_wi...') #6 /wp-content/plugins/wordpress-seo/admin/links/class-link-watcher.php(61): WPSEO_Link_Watcher->process(949, '[vc_row full_wi...') #7 /var/www/eviil in /wp-content/themes/shopkeeper-child/functions.php on line 14Please help. I use you plugin on every site I use.
The topic ‘Fatal error when using WooCommerce shortcode’ is closed to new replies.