仅在 wooCommerce 商店页面中显示弹出窗口



我正在尝试仅使用Cookie在WooCommerce商店页面中设置新闻通讯订阅弹出窗口。
问题:在Wordpress中设置cookie应该在函数中完成.php其中条件标签不会运行,如下所述:https://docs.woocommerce.com/document/conditional-tags/

有什么建议吗?
谢谢

如果您想显示弹出窗口或只想将任何脚本添加到商店页面 然后你必须在wp_head中使用is_shop()条件标签或wp_footer行动。

试试这个代码

function subscription_footer()
{
//for shop page only
if (is_shop())
{
//if cookie does not exist/set then perform your stuff.
if (!isset($_COOKIE['shop_subscribe']))
{
setcookie('shop_subscribe', 'yes', time() + (86400 * 30)); // 86400 = 1 day
$_COOKIE['shop_subscribe'] = 'yes';
//here you can write your html/js code for popup.
}
}
//print_r($_COOKIE);
}
add_action('wp_footer', 'subscription_footer');

此代码位于功能.php活动子主题(或主题)的文件或任何插件文件中。