/**
  * True if a composited bundle is seen as a NYP product.
  *
  * @param  boolean       $is_nyp
  * @param  WC_CP_Product $composited_product
  * @return double
  */
 public static function composited_bundle_is_nyp($is_nyp, $composited_product)
 {
     $product = $composited_product->get_product();
     if ($product->product_type === 'bundle') {
         if ($product->is_nyp() || $product->contains_nyp()) {
             $is_nyp = true;
         }
     }
     return $is_nyp;
 }
 /**
  * Get composited product.
  *
  * @param  string            $component_id
  * @param  int               $product_id
  * @return WC_Product|false
  */
 public function get_composited_product($component_id, $product_id)
 {
     if (isset($this->composited_products[$component_id][$product_id])) {
         $composited_product = $this->composited_products[$component_id][$product_id];
     } else {
         $composited_product = new WC_CP_Product($product_id, $component_id, $this);
         if (!$composited_product->exists()) {
             return false;
         }
         $this->composited_products[$component_id][$product_id] = $composited_product;
     }
     return $composited_product;
 }
						<a class="component_option_thumbnail_tap" href="#" ></a>
						<div class="image thumbnail_image" title="<?php 
        echo esc_attr($title);
        ?>
"><?php 
        if (has_post_thumbnail($product_id)) {
            echo get_the_post_thumbnail($product_id, apply_filters('woocommerce_composite_component_option_image_size', 'shop_catalog'));
        } else {
            echo apply_filters('woocommerce_composite_component_option_image_placeholder', sprintf('<img src="%s" alt="%s" />', wc_placeholder_img_src(), __('Placeholder', 'woocommerce')), $product_id, $component_id, $product->id);
        }
        ?>
</div>
						<div class="thumbnail_description">
							<h5 class="thumbnail_title title">
								<?php 
        echo apply_filters('woocommerce_composited_product_thumbnail_title', WC_CP_Product::get_title_string($title), $quantity_string, $price_string, $product_id, $component_id, $product);
        ?>
							</h5>
							<span class="thumbnail_price price"><?php 
        $composited_product->add_filters();
        echo $composited_product->get_product()->get_price_html();
        $composited_product->remove_filters();
        ?>
							</span>
						</div>
					</div>

				</li><?php 
    }
    ?>
</ul><?php 
        $image_src = $attachment ? current($attachment) : false;
    } else {
        $image_src = wc_placeholder_img_src();
    }
    $title = $composited_product->get_product()->get_title();
    $quantity_string = $quantity_min == $quantity_max && $quantity_min > 1 ? $quantity_min : '';
    $price_string = $composited_product->get_price_string();
    ?>
<option data-title="<?php 
    echo esc_attr($title);
    ?>
" data-image_src="<?php 
    echo esc_attr($image_src);
    ?>
" value="<?php 
    echo $product_id;
    ?>
" <?php 
    echo selected($selected_option, $product_id, false);
    ?>
><?php 
    echo apply_filters('woocommerce_composited_product_dropdown_title', WC_CP_Product::get_title_string($title, '', $price_string), $quantity_string, $price_string, $product_id, $component_id, $product);
    ?>
</option><?php 
}
?>
</select>
		</div>
		<div class="cp_clearfix"></div>
	</div>
</div>
Пример #5
0
<?php

/**
 * Composited Product Title.
 *
 * Override this template by copying it to 'yourtheme/woocommerce/composited-product/title.php'.
 *
 * On occasion, this template file may need to be updated and you (the theme developer) will need to copy the new files to your theme to maintain compatibility.
 * We try to do this as little as possible, but it does happen.
 * When this occurs the version of the template file will be bumped and the readme will list any important changes.
 *
 * @version  3.1.1
 */
// Exit if accessed directly.
if (!defined('ABSPATH')) {
    exit;
}
?>
<h4 class="composited_product_title product_title"><?php 
echo WC_CP_Product::get_title_string(apply_filters('woocommerce_composited_product_title', $title, $product_id, $component_id, $composite), $quantity);
?>
</h4>
 /**
  * Tweak composite container name.
  *
  * @param  bool 	$show
  * @param  array 	$cart_item
  * @param  string 	$cart_item_key
  * @return bool
  */
 function wc_cp_cart_widget_container_item_name($name, $cart_item, $cart_item_key)
 {
     if (isset($cart_item['composite_children'])) {
         $name = WC_CP_Product::get_title_string($name, $cart_item['quantity']);
     }
     return $name;
 }
 /**
  * Order API Modification #3 (unused):
  *
  * Exclude/modify order items depending on the "per-item pricing" and "per-item shipping" settings.
  *
  * @param  array    $items
  * @param  WC_Order $order
  * @return array
  */
 public function order_items($items, $order)
 {
     $return_items = $items;
     if (false === self::$override_order_items_filters && apply_filters('woocommerce_composite_filter_order_items', false, $order)) {
         $return_items = array();
         foreach ($items as $item_id => $item) {
             if (isset($item['composite_children']) && isset($item['composite_cart_key'])) {
                 /*
                  * Do not export bundled items that are shipped packaged in the container ("bundled" shipping).
                  * Instead, add their totals into the container and create a container "Contents" meta field to provide a description of the included products.
                  */
                 if (isset($item['per_product_shipping']) && $item['per_product_shipping'] === 'no') {
                     $bundle_key = $item['composite_cart_key'];
                     // Aggregate contents
                     $meta_key = __('Contents', 'woocommerce-composite-products');
                     $meta_values = array();
                     // Aggregate prices
                     $bundle_totals = array('line_subtotal' => $item['line_subtotal'], 'line_total' => $item['line_total'], 'line_subtotal_tax' => $item['line_subtotal_tax'], 'line_tax' => $item['line_tax'], 'line_tax_data' => maybe_unserialize($item['line_tax_data']));
                     foreach ($items as $child_item_id => $child_item) {
                         if (isset($child_item['composite_parent']) && $child_item['composite_parent'] === $bundle_key && isset($child_item['bundled_shipping']) && $child_item['bundled_shipping'] === 'no') {
                             /*
                              * Aggregate bundled items shipped within the container as "Contents" meta of container.
                              */
                             $child = $order->get_product_from_item($child_item);
                             if (!$child) {
                                 continue;
                             }
                             $sku = $child->get_sku();
                             if (!$sku) {
                                 $sku = '#' . (isset($child->variation_id) ? $child->variation_id : $child->id);
                             }
                             $title = WC_CP_Product::get_title_string($child_item['name'], $child_item['qty']);
                             $meta = '';
                             if (!empty($child_item['item_meta'])) {
                                 if (!empty($child_item['item_meta'][__('Part of', 'woocommerce-composite-products')])) {
                                     unset($child_item['item_meta'][__('Part of', 'woocommerce-composite-products')]);
                                 }
                                 if (WC_CP_Core_Compatibility::is_wc_version_gte_2_4()) {
                                     $item_meta = new WC_Order_Item_Meta($child_item);
                                 } else {
                                     $item_meta = new WC_Order_Item_Meta($child_item['item_meta']);
                                 }
                                 $formatted_meta = $item_meta->display(true, true, '_', ', ');
                                 if ($formatted_meta) {
                                     $meta = $formatted_meta;
                                 }
                             }
                             $meta_values[] = WC_CP_Helpers::format_product_title($title, $sku, $meta, true);
                             /*
                              * Aggregate the totals of bundled items shipped within the container into the container price.
                              */
                             $bundle_totals['line_subtotal'] += $child_item['line_subtotal'];
                             $bundle_totals['line_total'] += $child_item['line_total'];
                             $bundle_totals['line_subtotal_tax'] += $child_item['line_subtotal_tax'];
                             $bundle_totals['line_tax'] += $child_item['line_tax'];
                             $child_item_line_tax_data = maybe_unserialize($child_item['line_tax_data']);
                             $bundle_totals['line_tax_data']['total'] = array_merge($bundle_totals['line_tax_data']['total'], $child_item_line_tax_data['total']);
                         }
                     }
                     $items[$item_id]['line_tax_data'] = serialize($bundle_totals['line_tax_data']);
                     $items[$item_id] = array_merge($item, $bundle_totals);
                     if (WC_CP_Core_Compatibility::is_wc_version_gte_2_4()) {
                         // Terrible hack: add an element in the 'item_meta_array' array (a puppy somewhere just died).
                         if (!empty($items[$item_id]['item_meta_array'])) {
                             $keys = array_keys($items[$item_id]['item_meta_array']);
                             $last_key = end($keys);
                             $entry = new stdClass();
                             $entry->key = $meta_key;
                             $entry->value = implode(', ', $meta_values);
                             $items[$item_id]['item_meta_array'][$last_key + 1] = $entry;
                         }
                     }
                     $items[$item_id]['item_meta'][$meta_key] = implode(', ', $meta_values);
                     $return_items[$item_id] = $items[$item_id];
                     /*
                      * If the bundled items are shipped individually ("per-item" shipping), do not export the container unless it has a non-zero price.
                      * In this case, instead of marking it as virtual, modify its weight and dimensions (tiny values) to avoid any extra shipping costs and ensure that its value is included in the shipment - @see 'get_product_from_item'.
                      */
                 } elseif ($item['line_total'] > 0) {
                     $return_items[$item_id] = $items[$item_id];
                 }
             } elseif (isset($item['composite_parent']) && isset($item['composite_cart_key'])) {
                 if (!isset($item['bundled_shipping']) || $item['bundled_shipping'] === 'yes') {
                     $return_items[$item_id] = $items[$item_id];
                 }
             } else {
                 $return_items[$item_id] = $items[$item_id];
             }
         }
     }
     return $return_items;
 }