When I try to add the [woocommerce_messages] or [shop_messages] shortcodes in a post or page while Yoast SEO is active, I get a fatal error upon saving the post/page.
Fatal error: Uncaught Error: Call to undefined function wc_print_notices() in J:\MAMP\htdocs\langhe\wp-content\plugins\woocommerce\includes\class-wc-shortcodes.php:578 Stack trace: #0 J:\MAMP\htdocs\langhe\wp-includes\shortcodes.php(345): WC_Shortcodes::shop_messages('', '', 'woocommerce_mes...') #1 [internal function]: do_shortcode_tag(Array) #2 J:\MAMP\htdocs\langhe\wp-includes\shortcodes.php(223): preg_replace_callback('/\\[(\\[?)(woocom...', 'do_shortcode_ta...', '[woocommerce_me...') #3 J:\MAMP\htdocs\langhe\wp-includes\class-wp-hook.php(298): do_shortcode('[woocommerce_me...') #4 J:\MAMP\htdocs\langhe\wp-includes\plugin.php(203): WP_Hook->apply_filters('[woocommerce_me...', Array) #5 J:\MAMP\htdocs\langhe\wp-content\plugins\wordpress-seo\admin\links\class-link-watcher.php(45): apply_filters('the_content', '[woocommerce_me...') #6 J:\MAMP\htdocs\langhe\wp-includes\class-wp-hook.php(300): WPSEO_Link_Watcher->save_post(65459, Object(WP_Post)) #7 J:\MAMP\htdocs\langhe\wp-includes\class-wp-hook.php(323): WP_Hook->apply_f in J:\MAMP\htdocs\langhe\wp-content\plugins\woocommerce\includes\class-wc-shortcodes.php on line 578
I expected the page/post to be saved normally :-)
Thank you for reporting this bug.
It's marked as backlog, so it appears in the to do-list of our development team.
Hi Ben,
thank you for the reply!
Glad to see this is on the to-do list. Thanks a bunch! :)
Encountering the exact same issue with Woo Coomerce and Yoast. Any updates on a fix or workaround?
Running Woocommerce 3.5.0 and Yoast SEO 9.0.2 on Wordpres 4.9.1.
As this is using different versions of both Yoast and WooCommerce, should I open a new ticket or would that be creating a duplicate issue ?
@lcenine that would be a duplicate, so your comment that it still happens with the latest versions is great.
Looking at the fatal error message, it seems to originate in WooCommerce. Has the issue been reported there as well?
@benvaassen I did open a ticket over at WooCommerce. The initial advice was to disable plugins to see if that fixed the issue. The only other plugin I had was Yoast and disabling it did indeed fix the issue (or at least give me a way to save pages).
Please inform the customer of conversation # 457261 when this conversation has been closed.
@iamazik Do you have a link to that conversation? I cannot find it. Many Thanks!
@lcenine The conversation we are referring here is for our own purpose to update the relevant issue. You won't be able to see that, nor you need to.
I can confirm that I get this same exact error:
/public_html/wp-content/plugins/wordpress-seo/admin/links/class-link-watcher.php(119): apply_filters('the_content', '[shop_messages]') #6 /hom in /public_html/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php on line 588
When disabling yoast SEO, the error is no longer occurs.
I didn't check all details. It's possible to disable "Text link counter" or "remove shortcode for admin requests" .
I've tried to create simple snippet:
add_action( 'admin_init', function() {
if ( ! empty( $GLOBALS['pagenow'] ) && in_array( $GLOBALS['pagenow'], array( 'post-new.php', 'post.php' ), true ) ) {
remove_shortcode( 'shop_messages' );
}
} );
I didn't check all possible scenarios, but it should work.
@stodorovic Are you adding that into functions.php or elsewhere ?
@lcenine You could add it anywhere - child theme (fuctions.php), custom plugin or create simple must use plugin.
I've used anonymous function which requries PHP >= 5.3. I didn't test it to PHP 7.3 (regarding that this snippet uses superglobals in anonymous function), but it should work.
this will not work with drag and drop theme builders.
It works with WP Bakery Frontend Editor. It's possible that will work with other editors because WooCommerce loads function _wc_print_notices_ if it's frontend request (but probably there is some editor which doesn't work). Anyway, WooCommerce doesn't load this function for REST API and CRON requests (it's possible fatal error). I've caught error while CRON process was running. Also, it's possible error with Gutenberg (REST API).
I've tried to create better PHP snippet which is compromise between functionality and performance:
if ( basename( $_SERVER['PHP_SELF'] ) !== 'index.php' ||
( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' )
) {
add_filter( 'the_content', function( $content ) {
static $done = false;
if ( $done ) {
return $content;
}
$done = true;
if ( ! function_exists( 'wc_print_notices' ) ) {
remove_shortcode( 'woocommerce_messages' );
remove_shortcode( 'shop_messages' );
}
return $content;
}, 9 );
}
It still isn't perfect,, but it worked in my tests (CRON, REST, ...).
PR https://github.com/woocommerce/woocommerce/pull/22855 (which fixes this issue) is merged. It'll be fixed in WooCommerce 3.6.0.
I just checked and it's fixed in WooCommerce 3.6 (which is released few days ago). @Djennez Could you check? I think that we could close this issue.
Can't reproduce this. Closing :)
Most helpful comment
Thank you for reporting this bug.
It's marked as backlog, so it appears in the to do-list of our development team.