2

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Rosh_LK
  • 680
  • 1
  • 15
  • 36

1 Answers1

4

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' );
}
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
Rosh_LK
  • 680
  • 1
  • 15
  • 36