Skip to content

Instantly share code, notes, and snippets.

@mahdiyazdani
Created June 5, 2020 13:06
Show Gist options
  • Save mahdiyazdani/d8198c62ac863fe36b1e313d62c18ba0 to your computer and use it in GitHub Desktop.
Save mahdiyazdani/d8198c62ac863fe36b1e313d62c18ba0 to your computer and use it in GitHub Desktop.
Determine whether the WooCommerce store is set to be closed or not
<?php
/**
* Determine whether the store is set to be closed or not!
* You can place PHP snippets at the bottom of your child theme `functions.php` file (before "?>" if you have it).
*
* @param object $wp_admin_bar
* @return void
*/
function prefix_is_shop_closed( $wp_admin_bar ) {
// Bail early, in case the plugin is not activated.
if ( ! defined( 'WSVPRO_SLUG' ) ) {
return;
}
// Get the nodes produced by plugins and core.
$all_toolbar_nodes = $wp_admin_bar->get_nodes();
// Loop through each node to see if there is one matched with the plugin slug.
foreach ( $all_toolbar_nodes as $node ) {
if ( WSVPRO_SLUG === $node->id ) {
echo 'The store is closed!'; // Do something here...
}
}
}
add_action( 'admin_bar_menu', 'prefix_is_shop_closed', PHP_INT_MAX );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment