/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return array */ private function get_product_data($product) { return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height(), 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array()); }
/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return WC_Product */ private function get_product_data($product) { return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array()); }
$end_date = strtotime(tribe_get_end_date(get_the_ID(), false, 'Y-m-d G:i') . $gmt_offset); } $start_date = null; if (!empty($ticket->start_date)) { $start_date = strtotime($ticket->start_date . $gmt_offset); } if ((empty($start_date) || time() > $start_date) && (empty($end_date) || time() < $end_date)) { $is_there_any_product = true; echo sprintf('<input type="hidden" name="product_id[]" value="%d">', $ticket->ID); echo '<tr>'; echo '<td class="woocommerce">'; if ($product->is_in_stock()) { // Max quantity will be left open if backorders allowed, restricted to 1 if the product is // constrained to be sold individually or else set to the available stock quantity $max_quantity = $product->backorders_allowed() ? '' : $product->get_stock_quantity(); $max_quantity = $product->is_sold_individually() ? 1 : $max_quantity; woocommerce_quantity_input(array('input_name' => 'quantity_' . $ticket->ID, 'input_value' => 0, 'min_value' => 0, 'max_value' => $max_quantity)); $is_there_any_product_to_sell = true; } else { echo '<span class="tickets_nostock">' . esc_html__('Out of stock!', 'tribe-wootickets') . '</span>'; } echo '</td>'; echo '<td nowrap="nowrap" class="tickets_name">'; echo $ticket->name; echo '</td>'; echo '<td class="tickets_price">'; echo $this->get_price_html($product); //echo '<a class="member_discount nav_login" href="'; //echo esc_url(home_url('/')); //echo 'wp-admin'; //echo '">Login for member discount</a>';
/** * Add a product to the cart * * @param string $product_id contains the id of the product to add to the cart * @param string $quantity contains the quantity of the item to add * @param int $variation_id * @param array $variation attribute values * @param array $cart_item_data extra cart item data we want to pass into the item * @return bool */ function add_to_cart($product_id, $quantity = 1, $variation_id = '', $variation = '', $cart_item_data = array()) { global $woocommerce; if ($quantity < 1) { return false; } // Load cart item data - may be added by other plugins $cart_item_data = (array) apply_filters('woocommerce_add_cart_item_data', $cart_item_data, $product_id); // Generate a ID based on product ID, variation ID, variation data, and other cart item data $cart_id = $this->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data); // See if this product and its options is already in the cart $cart_item_key = $this->find_product_in_cart($cart_id); if ($variation_id > 0) { $product_data = new WC_Product_Variation($variation_id); } else { $product_data = new WC_Product($product_id); } // Force quantity to 1 if sold individually if ($product_data->is_sold_individually()) { $quantity = 1; } // Type/Exists check if ($product_data->is_type('external') || !$product_data->exists()) { $woocommerce->add_error(__('This product cannot be purchased.', 'woocommerce')); return false; } // Price set check if ($product_data->get_price() === '') { $woocommerce->add_error(__('This product cannot be purchased - the price is not yet set.', 'woocommerce')); return false; } // Stock check - only check if we're managing stock and backorders are not allowed if (!$product_data->has_enough_stock($quantity)) { $woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock. We have %s in stock.', 'woocommerce'), $product_data->get_stock_quantity())); return false; } elseif (!$product_data->is_in_stock()) { $woocommerce->add_error(__('You cannot add that product to the cart since the product is out of stock.', 'woocommerce')); return false; } // Downloadable/virtual qty check if ($product_data->is_sold_individually()) { $in_cart_quantity = $cart_item_key ? $this->cart_contents[$cart_item_key]['quantity'] + $quantity : $quantity; // If its greater than 1, its already in the cart if ($in_cart_quantity > 1) { $woocommerce->add_error(sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('You already have this item in your cart.', 'woocommerce'))); return false; } } // Stock check - this time accounting for whats already in-cart $product_qty_in_cart = $this->get_cart_item_quantities(); if ($product_data->managing_stock()) { // Variations if ($variation_id && $product_data->variation_has_stock) { if (isset($product_qty_in_cart[$variation_id]) && !$product_data->has_enough_stock($product_qty_in_cart[$variation_id] + $quantity)) { $woocommerce->add_error(sprintf(__('<a href="%s" class="button">%s</a> You cannot add that amount to the cart — we have %s in stock and you already have %s in your cart.', 'woocommerce'), get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), $product_data->get_stock_quantity(), $product_qty_in_cart[$variation_id])); return false; } // Products } else { if (isset($product_qty_in_cart[$product_id]) && !$product_data->has_enough_stock($product_qty_in_cart[$product_id] + $quantity)) { $woocommerce->add_error(sprintf(__('<a href="%s" class="button">%s</a> You cannot add that amount to the cart — we have %s in stock and you already have %s in your cart.', 'woocommerce'), get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), $product_data->get_stock_quantity(), $product_qty_in_cart[$product_id])); return false; } } } // If cart_item_key is set, the item is already in the cart if ($cart_item_key) { $new_quantity = $quantity + $this->cart_contents[$cart_item_key]['quantity']; $this->set_quantity($cart_item_key, $new_quantity); } else { $cart_item_key = $cart_id; // Add item after merging with $cart_item_data - hook to allow plugins to modify cart item $this->cart_contents[$cart_item_key] = apply_filters('woocommerce_add_cart_item', array_merge($cart_item_data, array('product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data)), $cart_item_key); } do_action('woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data); $woocommerce->cart_has_contents_cookie(true); $this->set_session(); return true; }
/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return WC_Product */ private function get_product_data($product, $fields = null) { if ($fields) { $field_list = explode(',', $fields); } $product_data = array(); if (!$fields || $fields && in_array('title', $field_list)) { $product_data['title'] = $product->get_title(); } if (!$fields || $fields && in_array('id', $field_list)) { $product_data['id'] = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id; } if (!$fields || $fields && in_array('created_at', $field_list)) { $product_data['created_at'] = $this->server->format_datetime($product->get_post_data()->post_date_gmt); } if (!$fields || $fields && in_array('updated_at', $field_list)) { $product_data['updated_at'] = $this->server->format_datetime($product->get_post_data()->post_modified_gmt); } if (!$fields || $fields && in_array('type', $field_list)) { $product_data['type'] = $product->product_type; } if (!$fields || $fields && in_array('status', $field_list)) { $product_data['status'] = $product->get_post_data()->post_status; } if (!$fields || $fields && in_array('downloadable', $field_list)) { $product_data['downloadable'] = $product->is_downloadable(); } if (!$fields || $fields && in_array('virtual', $field_list)) { $product_data['virtual'] = $product->is_virtual(); } if (!$fields || $fields && in_array('permalink', $field_list)) { $product_data['permalink'] = $product->get_permalink(); } if (!$fields || $fields && in_array('sku', $field_list)) { $product_data['sku'] = $product->get_sku(); } if (!$fields || $fields && in_array('price', $field_list)) { $product_data['price'] = $product->get_price(); } if (!$fields || $fields && in_array('regular_price', $field_list)) { $product_data['regular_price'] = $product->get_regular_price(); } if (!$fields || $fields && in_array('sale_price', $field_list)) { $product_data['sale_price'] = $product->get_sale_price() ? $product->get_sale_price() : null; } if (!$fields || $fields && in_array('price_html', $field_list)) { $product_data['price_html'] = $product->get_price_html(); } if (!$fields || $fields && in_array('taxable', $field_list)) { $product_data['taxable'] = $product->is_taxable(); } if (!$fields || $fields && in_array('tax_status', $field_list)) { $product_data['tax_status'] = $product->get_tax_status(); } if (!$fields || $fields && in_array('tax_class', $field_list)) { $product_data['tax_class'] = $product->get_tax_class(); } if (!$fields || $fields && in_array('managing_stock', $field_list)) { $product_data['managing_stock'] = $product->managing_stock(); } if (!$fields || $fields && in_array('stock_quantity', $field_list)) { $product_data['stock_quantity'] = $product->get_stock_quantity(); } if (!$fields || $fields && in_array('in_stock', $field_list)) { $product_data['in_stock'] = $product->is_in_stock(); } if (!$fields || $fields && in_array('backorders_allowed', $field_list)) { $product_data['backorders_allowed'] = $product->backorders_allowed(); } if (!$fields || $fields && in_array('backordered', $field_list)) { $product_data['backordered'] = $product->is_on_backorder(); } if (!$fields || $fields && in_array('sold_individually', $field_list)) { $product_data['sold_individually'] = $product->is_sold_individually(); } if (!$fields || $fields && in_array('purchaseable', $field_list)) { $product_data['purchaseable'] = $product->is_purchasable(); } if (!$fields || $fields && in_array('featured', $field_list)) { $product_data['featured'] = $product->is_featured(); } if (!$fields || $fields && in_array('visible', $field_list)) { $product_data['visible'] = $product->is_visible(); } if (!$fields || $fields && in_array('catalog_visibility', $field_list)) { $product_data['catalog_visibility'] = $product->visibility; } if (!$fields || $fields && in_array('on_sale', $field_list)) { $product_data['on_sale'] = $product->is_on_sale(); } if (!$fields || $fields && in_array('product_url', $field_list)) { $product_data['product_url'] = $product->is_type('external') ? $product->get_product_url() : ''; } if (!$fields || $fields && in_array('button_text', $field_list)) { $product_data['button_text'] = $product->is_type('external') ? $product->get_button_text() : ''; } if (!$fields || $fields && in_array('weight', $field_list)) { $product_data['weight'] = $product->get_weight() ? $product->get_weight() : null; } if (!$fields || $fields && in_array('dimensions', $field_list)) { $product_data['dimensions'] = array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')); } if (!$fields || $fields && in_array('shipping_required', $field_list)) { $product_data['shipping_required'] = $product->needs_shipping(); } if (!$fields || $fields && in_array('shipping_taxable', $field_list)) { $product_data['shipping_taxable'] = $product->is_shipping_taxable(); } if (!$fields || $fields && in_array('shipping_class', $field_list)) { $product_data['shipping_class'] = $product->get_shipping_class(); } if (!$fields || $fields && in_array('shipping_class_id', $field_list)) { $product_data['shipping_class_id'] = 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null; } if (!$fields || $fields && in_array('description', $field_list)) { $product_data['description'] = wpautop(do_shortcode($product->get_post_data()->post_content)); } if (!$fields || $fields && in_array('short_description', $field_list)) { $product_data['short_description'] = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt); } if (!$fields || $fields && in_array('reviews_allowed', $field_list)) { $product_data['reviews_allowed'] = 'open' === $product->get_post_data()->comment_status; } if (!$fields || $fields && in_array('average_rating', $field_list)) { $product_data['average_rating'] = wc_format_decimal($product->get_average_rating(), 2); } if (!$fields || $fields && in_array('rating_count', $field_list)) { $product_data['rating_count'] = (int) $product->get_rating_count(); } if (!$fields || $fields && in_array('related_ids', $field_list)) { $product_data['related_ids'] = array_map('absint', array_values($product->get_related())); } if (!$fields || $fields && in_array('upsell_ids', $field_list)) { $product_data['upsell_ids'] = array_map('absint', $product->get_upsells()); } if (!$fields || $fields && in_array('cross_sell_ids', $field_list)) { $product_data['cross_sell_ids'] = array_map('absint', $product->get_cross_sells()); } if (!$fields || $fields && in_array('parent_id', $field_list)) { $product_data['parent_id'] = $product->post->post_parent; } if (!$fields || $fields && in_array('categories', $field_list)) { $product_data['categories'] = wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')); } if (!$fields || $fields && in_array('tags', $field_list)) { $product_data['tags'] = wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')); } if (!$fields || $fields && in_array('images', $field_list)) { $product_data['images'] = $this->get_images($product); } if (!$fields || $fields && in_array('featured_src', $field_list)) { $product_data['featured_src'] = (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)); } if (!$fields || $fields && in_array('attributes', $field_list)) { $product_data['attributes'] = $this->get_attributes($product); } if (!$fields || $fields && in_array('downloads', $field_list)) { $product_data['downloads'] = $this->get_downloads($product); } if (!$fields || $fields && in_array('download_limit', $field_list)) { $product_data['download_limit'] = (int) $product->download_limit; } if (!$fields || $fields && in_array('download_expiry', $field_list)) { $product_data['download_expiry'] = (int) $product->download_expiry; } if (!$fields || $fields && in_array('download_type', $field_list)) { $product_data['download_type'] = $product->download_type; } if (!$fields || $fields && in_array('purchase_note', $field_list)) { $product_data['purchase_note'] = wpautop(do_shortcode(wp_kses_post($product->purchase_note))); } if (!$fields || $fields && in_array('total_sales', $field_list)) { $product_data['total_sales'] = metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0; } if (!$fields || $fields && in_array('variations', $field_list)) { $product_data['variations'] = array(); } if (!$fields || $fields && in_array('parent', $field_list)) { $product_data['parent'] = array(); } if (!$fields || $fields && in_array('grouped_products', $field_list)) { $product_data['grouped_products'] = array(); } if (!$fields || $fields && in_array('menu_order', $field_list)) { $product_data['menu_order'] = $product->post->menu_order; } return $product_data; }
/** * A bundle is sold individually if it is marked as an "individually-sold" product, or if all bundled items are sold individually. * * @return boolean sold individually status */ public function is_sold_individually() { if (!$this->is_synced()) { $this->sync_bundle(); } return parent::is_sold_individually() || $this->all_items_sold_individually; }
function load_bundle_data() { global $woocommerce_bundles; // stores bundle pricing strategy info and price table $this->bundle_price_data = array(); $this->bundle_price_data['currency_symbol'] = get_woocommerce_currency_symbol(); $this->bundle_price_data['woocommerce_price_num_decimals'] = (int) get_option('woocommerce_price_num_decimals'); $this->bundle_price_data['woocommerce_currency_pos'] = get_option('woocommerce_currency_pos'); $this->bundle_price_data['woocommerce_price_decimal_sep'] = stripslashes(get_option('woocommerce_price_decimal_sep')); $this->bundle_price_data['woocommerce_price_thousand_sep'] = stripslashes(get_option('woocommerce_price_thousand_sep')); $this->bundle_price_data['woocommerce_price_trim_zeros'] = get_option('woocommerce_price_trim_zeros'); $this->bundle_price_data['free'] = __('Free!', 'woocommerce'); $this->bundle_price_data['per_product_pricing'] = $this->per_product_pricing_active; $this->bundle_price_data['prices'] = array(); $this->bundle_price_data['regular_prices'] = array(); $this->bundle_price_data['total'] = $this->per_product_pricing_active ? (double) 0 : (double) ($this->get_price() == '' ? -1 : $this->get_price()); $this->bundle_price_data['regular_total'] = $this->per_product_pricing_active ? (double) 0 : (double) $this->regular_price; $this->bundle_price_data['total_description'] = __('Total', 'woo-bundles') . ': '; $this->bundle_attributes = array(); $this->available_bundle_variations = array(); $this->selected_bundle_attributes = array(); $this->bundled_products = array(); foreach ($this->bundled_item_ids as $bundled_item_id) { // remove suffix $sep = explode('_', $bundled_item_id); $product_id = $sep[0]; $bundled_product_post = get_post($product_id); if (get_post_status($product_id) != 'publish') { continue; } if ($this->is_wc_v2) { $bundled_product = get_product($product_id); } else { $bundled_product = new WC_Product($product_id); } $this->bundled_products[$bundled_item_id] = $bundled_product; if ($bundled_product->product_type == 'simple') { if (!$bundled_product->is_sold_individually()) { $this->sold_individually = false; } // price for simple products gets stored now, for variable products jquery gets the job done $this->bundle_price_data['prices'][$bundled_product->id] = (double) $bundled_product->get_price(); $this->bundle_price_data['regular_prices'][$bundled_product->id] = (double) $bundled_product->regular_price; // no variation data to load - product is simple $this->min_bundle_price = $this->min_bundle_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->get_price(); $this->min_bundle_regular_price = $this->min_bundle_regular_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->regular_price; $this->max_bundle_price = $this->max_bundle_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->get_price(); $this->max_bundle_regular_price = $this->max_bundle_regular_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->regular_price; } elseif ($bundled_product->product_type == 'variable') { // prepare price variable for jquery $this->bundle_price_data['prices'][$bundled_item_id] = 0; $this->bundle_price_data['regular_prices'][$bundled_item_id] = 0; // get all available attributes and settings $this->bundle_attributes[$bundled_item_id] = $bundled_product->get_variation_attributes(); $default_product_attributes = array(); if ($this->bundle_defaults_active[$bundled_item_id]) { $default_product_attributes = $this->bundle_defaults[$bundled_item_id]; } else { $default_product_attributes = (array) maybe_unserialize(get_post_meta($bundled_product_post->ID, '_default_attributes', true)); } $this->selected_bundle_attributes[$bundled_item_id] = apply_filters('woocommerce_product_default_attributes', $default_product_attributes); // calculate min-max variation prices $min_variation_regular_price = ''; $min_variation_sale_price = ''; $max_variation_regular_price = ''; $max_variation_sale_price = ''; foreach ($bundled_product->get_children() as $child_id) { $variation = $bundled_product->get_child($child_id); // stop here if this variation is not within the active set (prices will not include this variation) if ($this->variation_filters_active[$bundled_item_id]) { if (!is_array($this->allowed_variations[$bundled_item_id])) { continue; } if (!in_array($child_id, $this->allowed_variations[$bundled_item_id])) { continue; } } if ($variation instanceof WC_Product_Variation) { if (get_post_status($variation->get_variation_id()) != 'publish') { continue; } // Disabled if (!$variation->is_sold_individually()) { $this->sold_individually = false; } // variation min-max price calculation $variation_price = get_post_meta($child_id, '_price', true); $variation_sale_price = get_post_meta($child_id, '_sale_price', true); // Low price if (!is_numeric($min_variation_regular_price) || $variation_price < $min_variation_regular_price) { $min_variation_regular_price = $variation_price; } if ($variation_sale_price !== '' && (!is_numeric($min_variation_sale_price) || $variation_sale_price < $min_variation_sale_price)) { $min_variation_sale_price = $variation_sale_price; } // High price if (!is_numeric($max_variation_regular_price) || $variation_price > $max_variation_regular_price) { $max_variation_regular_price = $variation_price; } if ($variation_sale_price !== '' && (!is_numeric($max_variation_sale_price) || $variation_sale_price > $max_variation_sale_price)) { $max_variation_sale_price = $variation_sale_price; } // prepare available options $variation_attributes = $variation->get_variation_attributes(); $availability = $variation->get_availability(); if (!is_admin() && !$woocommerce_bundles->validate_stock($product_id, $variation->variation_id, get_post_meta($this->id, 'bundle_quantity_' . $bundled_item_id, true), true, true)) { $availability = array('availability' => __('Out of stock', 'woocommerce'), 'class' => 'out-of-stock'); } $availability_html = !empty($availability['availability']) ? apply_filters('woocommerce_stock_html', '<p class="stock ' . $availability['class'] . '">' . $availability['availability'] . '</p>', $availability['availability']) : ''; if (has_post_thumbnail($variation->get_variation_id())) { $attachment_id = get_post_thumbnail_id($variation->get_variation_id()); $attachment = wp_get_attachment_image_src($attachment_id, apply_filters('bundled_product_large_thumbnail_size', 'shop_single')); $image = $attachment ? current($attachment) : ''; $attachment = wp_get_attachment_image_src($attachment_id, 'full'); $image_link = $attachment ? current($attachment) : ''; $image_title = get_the_title($attachment_id); } else { $image = $image_link = $image_title = ''; } $this->available_bundle_variations[$bundled_item_id][] = apply_filters('woocommerce_available_variation', array('variation_id' => $variation->get_variation_id(), 'product_id' => $bundled_item_id, 'attributes' => $variation_attributes, 'image_src' => $image, 'image_link' => $image_link, 'image_title' => $image_title, 'price' => (double) $variation->get_price(), 'regular_price' => (double) $variation->regular_price, 'price_html' => $this->per_product_pricing_active ? '<span class="price">' . $variation->get_price_html() . '</span>' : '', 'availability_html' => $availability_html), $bundled_product, $variation); } } $add = $min_variation_sale_price === '' || $min_variation_regular_price < $min_variation_sale_price ? $min_variation_regular_price : $min_variation_sale_price; $this->min_bundle_price = $this->min_bundle_price + $this->bundled_item_quantities[$bundled_item_id] * $add; $this->min_bundle_regular_price = $this->min_bundle_regular_price + $this->bundled_item_quantities[$bundled_item_id] * $min_variation_regular_price; $add = $max_variation_sale_price === '' || $max_variation_regular_price < $max_variation_sale_price ? $max_variation_regular_price : $max_variation_sale_price; $this->max_bundle_price = $this->max_bundle_price + $this->bundled_item_quantities[$bundled_item_id] * $add; $this->max_bundle_regular_price = $this->max_bundle_regular_price + $this->bundled_item_quantities[$bundled_item_id] * $max_variation_regular_price; } } }