Hide or edit the quot;You cannot add another #39;xxx#39; to your cartquot; error message in WooCommerce 4.5+(隐藏或编辑您无法在WooCommerce 4.5+中将另一个错误消息添加到购物车的错误消息(Q;))
问题描述
通过我启用的产品设置单独销售:启用此选项将仅允许在单个订单中购买一件商品&qot; 将相同的产品添加到购物车时,会出现一条错误消息,因为我启用了此设置。错误消息是";您无法将另一个‘xxx’添加到您的购物车。我不想把同样的产品加到购物车里,所以这个很好用,而且 很好。
我的问题:
如何隐藏错误消息";您无法将另一个‘xxx’添加到您的购物车。
如果我使用css代码
.woocommerce-error {
display: none;
}
那么我们登录时的错误密码或电子邮件也会被隐藏,我不想再隐藏另一条错误消息。
是否可以实现仅隐藏此错误?
推荐答案
若要编辑邮件,您可以使用从WooCommerce 4.5.0开始的woocommerce_cart_product_cannot_add_another_message
筛选器挂钩。
/**
* Filters message about more than 1 product being added to cart.
*
* @since 4.5.0
* @param string $message Message.
* @param WC_Product $product_data Product data.
*/
function filter_woocommerce_cart_product_cannot_add_another_message( $message, $product_data ) {
// New text
$message = __( 'My new message', 'woocommerce' );
return $message;
}
add_filter( 'woocommerce_cart_product_cannot_add_another_message', 'filter_woocommerce_cart_product_cannot_add_another_message', 10, 2 );
若要完全隐藏邮件,只需替换
// New text
$message = __( 'My new message', 'woocommerce' );
与
// New text
$message = '';
但是,上述解决方案的问题在于,邮件现在已隐藏,但woocommerce-error
(红框)和view-cart
按钮仍显示。
因此,在使用筛选器挂钩时,您可以添加一些额外的jQuery来隐藏woocommerce-error
注意:尽管以下方法有效,但隐藏错误消息从来都不是一个好主意。这些都是有原因的,让客户意识到一些事情。因此,此解决方案有点"棘手"。
但要回答您的问题,您可以使用:
function filter_woocommerce_cart_product_cannot_add_another_message( $message, $product_data ) {
$message = '<div class="hide-this-error-message"></div>';
return $message;
}
add_filter( 'woocommerce_cart_product_cannot_add_another_message', 'filter_woocommerce_cart_product_cannot_add_another_message', 10, 2 );
function action_wp_footer() {
?>
<script>
jQuery(document).ready(function($) {
$( '.hide-this-error-message' ).closest( 'ul.woocommerce-error' ).hide();
});
</script>
<?php
}
add_action( 'wp_footer', 'action_wp_footer' );
这篇关于隐藏或编辑您无法在WooCommerce 4.5+中将另一个错误消息添加到购物车的错误消息(&Q;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:隐藏或编辑您无法在WooCommerce 4.5+中将另一个错误消息添加到购物车的错误消息(&Q;)


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01