WC_Cart::get_cart PHP Метод

get_cart() публичный Метод

Returns the contents of the cart in an array.
public get_cart ( ) : array
Результат array contents of the cart
    public function get_cart()
    {
        if (!did_action('wp_loaded')) {
            wc_doing_it_wrong(__FUNCTION__, __('Get cart should not be called before the wp_loaded action.', 'woocommerce'), '2.3');
        }
        if (!did_action('woocommerce_cart_loaded_from_session')) {
            $this->get_cart_from_session();
        }
        return array_filter((array) $this->cart_contents);
    }

Usage Example

Пример #1
0
 /**
  * Sets a cookie when the cart has something in it. Can be used by hosts to prevent caching if set.
  *
  * @access public
  * @param mixed $set
  * @return void
  */
 public function cart_has_contents_cookie($set)
 {
     if (!headers_sent()) {
         if ($set) {
             setcookie("woocommerce_items_in_cart", "1", 0, COOKIEPATH, COOKIE_DOMAIN, false);
             setcookie("woocommerce_cart_hash", md5(json_encode($this->cart->get_cart())), 0, COOKIEPATH, COOKIE_DOMAIN, false);
         } else {
             setcookie("woocommerce_items_in_cart", "0", time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false);
             setcookie("woocommerce_cart_hash", "0", time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false);
         }
     }
 }
All Usage Examples Of WC_Cart::get_cart
WC_Cart