Reputation: 700
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 missed anything, please correct me.
Upvotes: 2
Views: 10377
Reputation: 700
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' );
}
Upvotes: 5