'', 'style' => '')); ?>
$taxonomy) { if (false === $taxonomy->public) { unset($taxonomies[$tax_slug]); } } $taxonomies = array_map(function ($taxonomy) { return (object) array( 'slug' => $taxonomy->name, 'label' => $taxonomy->label, ); }, $taxonomies); $options = array(); foreach ($taxonomies as $slug => $taxonomy) { $options[] = (object) array( 'label' => $taxonomy->label, 'value' => 'taxonomy:' . $slug, 'model' => 'taxonomy_' . $slug . '_items', 'data_store' => 'taxonomy_' . $slug . '_data', ); } return $options; } /** * Get cart item data * * @since 1.0.0 * @return array */ public static function get_cart_item_data($cart_item) { $product = $cart_item['data']; $cart_item_data = array( 'weight' => 0, 'volume' => 0, 'quantity' => $cart_item['quantity'] ); $product_weight = $product->get_weight(); if (is_numeric($product_weight)) { $cart_item_data['weight'] = $product_weight * $cart_item['quantity']; } $length = $product->get_length(); $width = $product->get_width(); $height = $product->get_height(); if (is_numeric($length) && is_numeric($width) && is_numeric($height)) { $cart_item_data['volume'] = $length * $width * $height * $cart_item['quantity']; } return $cart_item_data; } /** * Get cart items data * * @since 1.0.0 * @return array */ public static function get_cart_items_data($args) { $args = wp_parse_args($args, array('type' => '', 'taxonomy' => '', 'allow_in' => array())); $terms_cart_items = array(); foreach (WC()->cart->get_cart() as $cart_key => $item) { if ($item['data']->is_virtual()) { continue; } if ('cart' === $args['type']) { $terms_cart_items[$cart_key] = self::get_cart_item_data($item); continue; } if ('product_shipping_class' === $args['type']) { $shipping_class_id = $item['data']->get_shipping_class_id(); if (empty($shipping_class_id) || (count($args['allow_in']) > 0 && !in_array($shipping_class_id, $args['allow_in']))) { continue; } $terms_cart_items[$cart_key] = self::get_cart_item_data($item); continue; } if ('taxonomy' == $args['type'] && !empty($args['taxonomy'])) { $cart_item_terms = wc_get_product_term_ids($item['product_id'], $args['taxonomy']); foreach ($cart_item_terms as $term_id) { if (isset($terms_cart_items[$cart_key]) || (count($args['allow_in']) > 0 && !in_array($term_id, $args['allow_in']))) { continue; } $terms_cart_items[$cart_key] = self::get_cart_item_data($item); } continue; } } return $terms_cart_items; } }