• Resolved zzbeck

    (@zzbeck)


    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 14

    Please help. I use you plugin on every site I use.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Michael Tiña

    (@mikes41720)

    Hi,

    We can’t offer support on custom code (needed to change core features of our plugin). Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

    Closed due to inactivity.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Fatal error when using WooCommerce shortcode’ is closed to new replies.