Add or remove woocommerce error messages

南笙酒味 提交于 2019-12-12 02:12:55

问题


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)


回答1:


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' );
}


来源:https://stackoverflow.com/questions/37043382/add-or-remove-woocommerce-error-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!