Php 购物车通知提醒链接到Woocommerce中的结帐

Php 购物车通知提醒链接到Woocommerce中的结帐,php,wordpress,woocommerce,cart,hook-woocommerce,Php,Wordpress,Woocommerce,Cart,Hook Woocommerce,在Woocommerce中,我正在寻找一种方法,当购物车有产品时,在主页或任何页面上显示一条短消息,提醒用户可以完成付款 感谢您的帮助。以下非常简单的代码片段将在购物车有物品时显示提醒(woocommerce通知): add_action('template_redirect', 'checkout_reminder'); function checkout_reminder() { // Not on checkout page if( ! WC()->cart->

在Woocommerce中,我正在寻找一种方法,当购物车有产品时,在主页或任何页面上显示一条短消息,提醒用户可以完成付款


感谢您的帮助。

以下非常简单的代码片段将在购物车有物品时显示提醒(woocommerce通知):

add_action('template_redirect', 'checkout_reminder');
function checkout_reminder() {
    // Not on checkout page
    if( ! WC()->cart->is_empty() && ! is_checkout() ){
        $link     = wc_get_checkout_url(); // Checkout Url
        $count    = WC()->cart->get_cart_contents_count(); // cart count

        // Add a notice
        wc_add_notice(  sprintf( __("You have %d item(s) in cart."), $count ) . ' ' .
            '<a href="' . $link . '" class="button">' . __("Go to checkout") . '</a>',
        'notice' );
    }
}
add_操作(“模板重定向”、“签出提醒”);
函数签出提示(){
//不在结帐页上
如果(!WC()->cart->is_empty()&&!is_checkout()){
$link=wc\u get\u checkout\u url();//签出url
$count=WC()->cart->get_cart_contents_count();//购物车计数
//添加通知
wc_添加_通知(sprintf(_uuu(“购物车中有%d个项目”),$count)。“”。
'',
“通知”);
}
}
代码进入活动子主题(或主题)的function.php文件。测试和工作


当购物车有商品时,以下非常简单的代码片段将显示一个提醒(woocommerce通知):

add_action('template_redirect', 'checkout_reminder');
function checkout_reminder() {
    // Not on checkout page
    if( ! WC()->cart->is_empty() && ! is_checkout() ){
        $link     = wc_get_checkout_url(); // Checkout Url
        $count    = WC()->cart->get_cart_contents_count(); // cart count

        // Add a notice
        wc_add_notice(  sprintf( __("You have %d item(s) in cart."), $count ) . ' ' .
            '<a href="' . $link . '" class="button">' . __("Go to checkout") . '</a>',
        'notice' );
    }
}
add_操作(“模板重定向”、“签出提醒”);
函数签出提示(){
//不在结帐页上
如果(!WC()->cart->is_empty()&&!is_checkout()){
$link=wc\u get\u checkout\u url();//签出url
$count=WC()->cart->get_cart_contents_count();//购物车计数
//添加通知
wc_添加_通知(sprintf(_uuu(“购物车中有%d个项目”),$count)。“”。
'',
“通知”);
}
}
代码进入活动子主题(或主题)的function.php文件。测试和工作


欢迎来到SO。请阅读:。“要求我们推荐或查找书籍、工具、软件库、教程或其他非网站资源的问题对于Stack Overflow来说是离题的,因为它们往往会吸引固执己见的答案和垃圾邮件。”你需要做适当的研究,看看是否能找到任何符合你需要的插件。如果你找不到,你需要建立你自己的。对不起,我没有看到:)欢迎使用SO。请阅读:。“要求我们推荐或查找书籍、工具、软件库、教程或其他非网站资源的问题对于Stack Overflow来说是离题的,因为它们往往会吸引固执己见的答案和垃圾邮件。”你需要做适当的研究,看看是否能找到任何符合你需要的插件。如果你找不到,你需要构建自己的。很抱歉,我没有看到:)非常感谢,那么我可以自定义在我的主题中放置此内容的位置吗?@gamalelwazery如前所述,它使用Woocommerce notices api功能,因此你不能自定义位置和“活动子主题(或主题)的function.php文件中的代码”。非常感谢,那么我可以自定义在我的主题中放在哪里吗?@gamalelwazery如前所述,它使用Woocommerce notices api功能,因此您不能自定义位置和“代码进入活动子主题(或主题)的function.php文件”。谢谢