Skip to content

Instantly share code, notes, and snippets.

@IliaDi
Created January 25, 2023 18:03
Show Gist options
  • Save IliaDi/a353bfad69bbf3a73ba1fed480837b36 to your computer and use it in GitHub Desktop.
Save IliaDi/a353bfad69bbf3a73ba1fed480837b36 to your computer and use it in GitHub Desktop.
Display a notice on the settings page if there are no Shipping Zones yet
function wc_csp_check_shipping_zones(){
global $current_screen;
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
if ( $screen_id == 'woocommerce_page_wc-settings'){
$zones = WC_Shipping_Zones::get_zones();
if ( empty($zones) ) {
echo '<div class="notice notice-warning is-dismissible">
<p>It appears that your store does not have any Shipping Zones yet. Before setting up Shipping Methods Restrictions, it will be necessary to create Shipping Zones with all available Shipping Methods. <a href="https://docs.woocommerce.com/document/setting-up-shipping-zones/">Learn more here</a>
</p>
</div>';
}
}
}
add_action('admin_notices', 'wc_csp_check_shipping_zones');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment