删除Checkout for WooCommerce上的“添加到购物车”和“购物车已更新”消息

时间:2019-04-30 08:23:49

标签: woocommerce

我在网上找到了下面的代码,效果很好。它创建一个“一页”结帐。唯一的问题是,更改产品数量时,结帐时会显示“购物车已更新”消息。我需要删除它。

这是我用来获取“一页”结帐的代码:

// creates a combined cart and checkout page
add_action( 'woocommerce_before_checkout_form', 'one_page_checkout', 5 );
function one_page_checkout() {
if ( is_wc_endpoint_url( 'order-received' ) ) return; ?>
<div class="one-page-checkout-cart"><?php echo do_shortcode('[woocommerce_cart]'); ?></div>
<?php
}

// on empty cart when on checkout, redirect to home page
add_action( 'template_redirect', 'redirect_on_empty_checkout' );
function redirect_on_empty_checkout() {
if ( is_cart() && is_checkout() && 0 == WC()->cart->get_cart_contents_count() && ! is_wc_endpoint_url( 'order-pay' ) && ! is_wc_endpoint_url( 'order-received' ) ) {
wp_safe_redirect( 'shop' );
exit; } }


// removes coupon field form checkout, do not use CSS for this
add_action( 'woocommerce_before_checkout_form', 'remove_checkout_coupon_form_for_one_page_checkout', 9 );
function remove_checkout_coupon_form_for_one_page_checkout(){
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
}

对于“购物车已更新”消息,这是我正在使用的代码。它在结帐时效果很好,但也删除了产品页面上的“添加到购物车”消息。

add_filter( 'woocommerce_add_message', 'unset_atc_html_from_one_page_checkout' );
function unset_atc_html_from_one_page_checkout() {
global $woocommerce;
if (is_checkout() ) {
add_filter('woocommerce_add_message', '__return_false');
}}

在将“添加到购物车”消息保留在产品页面上的同时,帮助您从结帐中删除“购物车更新”消息。

2 个答案:

答案 0 :(得分:1)

要在自定义结帐页面上删除“已更新购物车”或“ {$ product_name}已添加到购物车”消息,请使用以下命令:

add_filter( 'woocommerce_add_message', 'remove_cart_updated_message_from_checkout' );
function remove_cart_updated_message_from_checkout( $message ) {
    if ( is_checkout() && ( strpos($message, 'Cart updated') !== false
    || strpos($message, 'has been added to your cart') !== false ) ) {
        return false;
    }
    return $message;
}

代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。

答案 1 :(得分:0)

删除“[产品名称]已添加到您的购物车。”

data Selection v = Selection !v !Integer