添加或删除 woocommerce 错误消息 [英] Add or remove woocommerce error messages

查看:26
本文介绍了添加或删除 woocommerce 错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 TNT 开发这个运输成本生成器作为 WordPress woo-commerce 扩展.问题是如果有错误,我需要显示错误并限制用户结帐.我使用以下方法来做到这一点.问题是当用户输入正确的数据并管理完成的事情时,我如何删除此通知.

i am developing this shipping cost generator for TNT as a WordPress woo-commerce extention.the thing is if there is an error i need to show the error and restrict user from checkout.I used following method to do that. The problem is how i can remove this notice when the user entered the correct data and manage the thing done.

if (!empty($xml->ratedTransitTimeResponse->ratedProducts->ratedProduct[0]->quote->price)) {
    $cost+= (float)$xml->ratedTransitTimeResponse->ratedProducts->ratedProduct[0]->quote->price;
}
else wc_add_wp_error_notices(new WP_Error(1, 'Shipping cost error'));

当用户输入正确的数据时,用户可以继续,但错误仍然存​​在.我需要删除它!(我已经尝试了很多参考资料,所以如果我错过了什么,请纠正我.任何新的建议也很感激)

When user entered correct data user can proceed but still the error is there.I need to remove it! (I tried this far with lot of references so if i have miss anything please correct me.any new suggestions also appreciated)

推荐答案

woo-commerce 有自己的预定义功能,当时我不知道.使用 wc_add_notice 和 wc_clear_notices 解决了这个问题!

woo-commerce has their own predefined functions for this which i didn't know at that time.used wc_add_notice and wc_clear_notices solved the issue!

if(!empty($xml->ratedTransitTimeResponse->ratedProducts->ratedProduct[0]->quote->price)){

     $cost+=(float)$xml->ratedTransitTimeResponse->ratedProducts->ratedProduct[0]->quote->price;
     wc_clear_notices();
}                       
else
{   //wc_add_wp_error_notices(new WP_Error(1,'Shipping cost error'));
     wc_clear_notices();
     wc_add_notice( 'Shipping cost error', 'error' );
}

这篇关于添加或删除 woocommerce 错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆