与 Woocommerce 中的结帐相关联的购物车通知提醒
Cart notification reminder linked to checkout in Woocommerce
在 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' );
}
}
代码进入您的活动子主题(或主题)的 function.php 文件。已测试并有效。
在 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' );
}
}
代码进入您的活动子主题(或主题)的 function.php 文件。已测试并有效。