wordpress 如何删除WooCommerce中的“{产品}已从您的购物车中删除,因为它不能再购买,”消息?

slhcrj9b  于 2023-01-08  发布在  WordPress
关注(0)|答案(2)|浏览(155)

我不想让客户得到“...已从您的购物车中删除,因为它不能再购买...”WooCommerce消息时,在他们的购物车中的产品得到的从网上商店删除。

kcugc4gi

kcugc4gi1#

或者,您可以挂钩到特定的错误消息过滤器,捕获所有可能的翻译,并清空消息以防止其显示。
就像这样:

function customise_cart_item_removed_message( $message, $product ) {
    return '';
}
add_filter( 'woocommerce_cart_item_removed_message', 'customise_cart_item_removed_message', PHP_INT_MAX, 2 );

woocommerce_cart_item_removed_message过滤器挂钩是唯一的此错误,并在wp-content/plugins/woocommerce/includes/class-wc-cart-session.php中定义的第142行(WooCommerce版本6.2.1)。

4c8rllxm

4c8rllxm2#

尝试在主题的functions.php中添加以下代码

// Remove the "order again" button
remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );

// woocommerce remove message (en&es): [Item] has been removed from your cart because it can no longer be purchased. Please contact us for assistance.

function customize_wc_errors( $error ) {
    if ( strpos( $error, 'has been removed from your cart because' ) !== false ) {
        return '';
    } else if ( strpos( $error, 'ha sido eliminado de tu carrito ya que no' ) !== false ) {
        return '';
    } else {
        return $error; 
    }
}
add_filter( 'woocommerce_add_error', 'customize_wc_errors' );

相关问题