/**
  * Test wc_has_notice().
  *
  * @since 2.2
  */
 function test_wc_has_notice()
 {
     // negative
     wc_add_notice('Bogus Notice', 'success');
     $this->assertFalse(wc_has_notice('Legit Notice'));
     // positive
     wc_add_notice('One True Notice', 'notice');
     $this->assertTrue(wc_has_notice('One True Notice', 'notice'));
 }
 /**
  * Get any errors from querystring.
  */
 public function get_errors()
 {
     if (!empty($_GET['wc_error']) && ($error = sanitize_text_field($_GET['wc_error'])) && !wc_has_notice($error, 'error')) {
         wc_add_notice($error, 'error');
     }
 }
 public function maybe_cancel_checkout_with_paypal()
 {
     if (is_cart() && !empty($_GET['wc-gateway-ppec-clear-session'])) {
         $this->maybe_clear_session_data();
         if (!wc_has_notice(__('You have cancelled Checkout with PayPal. Please try to process your order again.', 'woocommerce-gateway-paypal-express-checkout'), 'notice')) {
             wc_add_notice(__('You have cancelled Checkout with PayPal. Please try to process your order again.', 'woocommerce-gateway-paypal-express-checkout'), 'notice');
         }
     }
 }
 /**
  * Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally.
  *
  * Loads all shipping methods which are hooked in.
  * If a $package is passed some methods may add themselves conditionally and zones will be used.
  *
  * @param array $package
  * @return array
  */
 public function load_shipping_methods($package = array())
 {
     if (!empty($package)) {
         $status_options = get_option('woocommerce_status_options', array());
         $shipping_zone = WC_Shipping_Zones::get_zone_matching_package($package);
         $this->shipping_methods = $shipping_zone->get_shipping_methods(true);
         // Debug output
         if (!empty($status_options['shipping_debug_mode']) && !defined('WOOCOMMERCE_CHECKOUT') && !wc_has_notice('Customer matched zone "' . $shipping_zone->get_zone_name() . '"')) {
             wc_add_notice('Customer matched zone "' . $shipping_zone->get_zone_name() . '"');
         }
     } else {
         $this->shipping_methods = array();
     }
     // For the settings in the backend, and for non-shipping zone methods, we still need to load any registered classes here.
     foreach ($this->get_shipping_method_class_names() as $method_id => $method_class) {
         $this->register_shipping_method($method_class);
     }
     // Methods can register themselves manually through this hook if necessary.
     do_action('woocommerce_load_shipping_methods', $package);
     // Return loaded methods
     return $this->get_shipping_methods();
 }
 /**
  * Does some housekeeping. Fires after the items have been passed through the get items from session filter. Because
  * that filter is not good for removing cart items, we need to work around that by doing it later, in the cart
  * loaded from session action.
  *
  * This checks cart items whether underlying subscriptions / renewal orders they depend exist. If not, they are
  * removed from the cart.
  *
  * @param $cart WC_Cart the one we got from session
  */
 public function cart_items_loaded_from_session($cart)
 {
     $removed_count_subscription = $removed_count_order = 0;
     foreach ($cart->cart_contents as $key => $item) {
         if (isset($item[$this->cart_item_key]['subscription_id']) && !wcs_is_subscription($item[$this->cart_item_key]['subscription_id'])) {
             $cart->remove_cart_item($key);
             $removed_count_subscription++;
             continue;
         }
         if (isset($item[$this->cart_item_key]['renewal_order_id']) && !'shop_order' == get_post_type($item[$this->cart_item_key]['renewal_order_id'])) {
             $cart->remove_cart_item($key);
             $removed_count_order++;
             continue;
         }
     }
     if ($removed_count_subscription) {
         $error_message = esc_html(_n('We couldn\'t find the original subscription for an item in your cart. The item was removed.', 'We couldn\'t find the original subscriptions for items in your cart. The items were removed.', $removed_count_subscription, 'woocommerce-subscriptions'));
         if (!wc_has_notice($error_message, 'notice')) {
             wc_add_notice($error_message, 'notice');
         }
     }
     if ($removed_count_order) {
         $error_message = esc_html(_n('We couldn\'t find the original renewal order for an item in your cart. The item was removed.', 'We couldn\'t find the original renewal orders for items in your cart. The items were removed.', $removed_count_order, 'woocommerce-subscriptions'));
         if (!wc_has_notice($error_message, 'notice')) {
             wc_add_notice($error_message, 'notice');
         }
     }
 }
 /**
  * Load shipping methods
  */
 public function load_shipping_methods($package)
 {
     // Register the main class
     woocommerce_register_shipping_method('WC_Shipping_Table_Rate');
     if (!$package) {
         return;
     }
     // Get zone for package
     $zone = woocommerce_get_shipping_zone($package);
     if (TABLE_RATE_SHIPPING_DEBUG) {
         $notice_text = 'Customer matched shipping zone <strong>' . $zone->zone_name . '</strong> (#' . $zone->zone_id . ')';
         if (!wc_has_notice($notice_text, 'notice')) {
             wc_add_notice($notice_text, 'notice');
         }
     }
     if ($zone->exists()) {
         // Register zone methods
         $zone->register_shipping_methods();
     }
 }