You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WooCommerce产品新增页面持续显示WordPress后台通知

Show Admin Notice Only on WooCommerce Add Product Page

Hey there! Your current code displays the SSL notice on all WordPress admin pages, but we can tweak it to only show up when you're on the WooCommerce add-new-product page specifically. Here's the adjusted solution:

Modified Code Snippet

add_action('admin_notices', 'check_https_on_add_product');

function check_https_on_add_product() {
    // Grab the current admin screen details
    $current_screen = get_current_screen();
    
    // Target only the WooCommerce add-new-product page
    if (isset($current_screen->id) && $current_screen->id === 'product' && isset($_GET['action']) && $_GET['action'] === 'add') {
        echo '<div class="notice notice-error"><p>You need to enable SSL</p></div>';
    }
}

Quick Breakdown of Changes:

  • Renamed the function to be more descriptive (check_https_on_add_product)
  • Added page-specific checks using get_current_screen():
    • $current_screen->id === 'product' ensures we're on a product-related admin page
    • $_GET['action'] === 'add' narrows it exclusively to the add new product page
  • Wrapped the notice text in a <p> tag to match WordPress admin styling standards

How to Implement:

Add this code to your theme's functions.php file, or use a custom code snippets plugin (like Code Snippets) to avoid losing changes when you update your theme.

内容的提问来源于stack exchange,提问作者user9739520

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:39:13