Last active
March 17, 2022 17:45
-
-
Save webaware/c6a6286026eb6a89e5a3 to your computer and use it in GitHub Desktop.
display WooCommerce notices in any page by shortcode [woocommerce_notices]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WooCommerce Notices Shortcode | |
Plugin URI: https://gist.github.com/webaware/c6a6286026eb6a89e5a3 | |
Description: display WooCommerce notices in any page by shortcode [woocommerce_notices] | |
Author: WebAware | |
Author URI: https://shop.webaware.com.au/ | |
*/ | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
add_shortcode('woocommerce_notices', function($attrs) { | |
if (function_exists('wc_notice_count') && wc_notice_count() > 0) { | |
?> | |
<div class="woocommerce-notices-shortcode woocommerce"> | |
<?php wc_print_notices(); ?> | |
</div> | |
<?php | |
} | |
}); |
@SteamDonkey please update with the current code, it should work OK now. It's because Yoast is doing its thing before WooCommerce has loaded everything.
blazingly fast fix and response, you're amazing, thank you!
it doesn't work anymore. I try it on woocommerce Version 3.7.1
Does not work for me either. I really would appreciate if the code could be updated since it's exactly the function I need but can't find anywhere else
Still works for me on 4.3.1. Great! Thank you!
Works great. Thanx.
One question though: How can I change the position of the WooCommerce notice? I've noticed that no matter where I put the shortcode, the message will always appear on top of pretty much everything.
T.i.a.
You are angel :*
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome and we've been using it for some time. However, we recently ran into an issue where, if the short code is on a page, and Yoast settings are edited, the save produces an error.
Fatal error: Call to undefined function wc_notice_count()
The error doesn't happen if the short code isn't on the page when the Yoast setting changes are saved.
Any ideas on why this might be happening?