コード例 #1
0
				<div class="images">
					<?php 
    echo $variation->get_image();
    ?>
				</div>
				<div class="summary">
					<p itemprop="name" class="product_title entry-title"><?php 
    echo $variation->get_title();
    ?>
</p>
					<?php 
    echo $variation->get_price_html();
    ?>
					<ul>
						<li><?php 
    echo WC_Bulk_Variations_Compatibility::wc_attribute_label($row_attribute);
    ?>
: <?php 
    echo woocommerce_bulk_variations_get_title($row_attribute, $field_data[$row_attribute]);
    ?>
</li>

						<?php 
    if ($variation->sku) {
        ?>
							<li><?php 
        echo $field_data['variation_data']['sku'];
        ?>
</li>
						<?php 
    }
 public function process_matrix_submission()
 {
     global $woocommerce;
     $items = $_POST['order_info'];
     $product_id = $_POST['product_id'];
     $adding_to_cart = wc_get_product($product_id);
     $added_count = 0;
     $failed_count = 0;
     $success_message = '';
     $error_message = '';
     foreach ($items as $item) {
         $q = floatval($item['quantity']) ? floatval($item['quantity']) : 0;
         if ($q) {
             $variation_id = empty($item['variation_id']) ? '' : absint($item['variation_id']);
             $missing_attributes = array();
             //For validation, since 2.4
             $variations = array();
             // Only allow integer variation ID - if its not set, redirect to the product page
             if (empty($variation_id)) {
                 //wc_add_notice( __( 'Please choose product options&hellip;', 'woocommerce' ), 'error' );
                 $failed_count++;
                 continue;
             }
             $attributes = $adding_to_cart->get_attributes();
             $variation = wc_get_product($variation_id);
             // Verify all attributes
             foreach ($attributes as $attribute) {
                 if (!$attribute['is_variation']) {
                     continue;
                 }
                 $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
                 if (isset($item['variation_data'][$taxonomy])) {
                     // Get value from post data
                     if ($attribute['is_taxonomy']) {
                         // Don't use wc_clean as it destroys sanitized characters
                         $value = sanitize_title(stripslashes($item['variation_data'][$taxonomy]));
                     } else {
                         $value = wc_clean(stripslashes($item['variation_data'][$taxonomy]));
                     }
                     // Get valid value from variation
                     $valid_value = $variation->variation_data[$taxonomy];
                     // Allow if valid
                     if ('' === $valid_value || $valid_value === $value) {
                         // Pre 2.4 handling where 'slugs' were saved instead of the full text attribute
                         if (!$attribute['is_taxonomy']) {
                             if ($value === sanitize_title($value) && version_compare(get_post_meta($product_id, '_product_version', true), '2.4.0', '<')) {
                                 $text_attributes = wc_get_text_attributes($attribute['value']);
                                 foreach ($text_attributes as $text_attribute) {
                                     if (sanitize_title($text_attribute) === $value) {
                                         $value = $text_attribute;
                                         break;
                                     }
                                 }
                             }
                         }
                         $variations[$taxonomy] = $value;
                         continue;
                     }
                 } else {
                     $missing_attributes[] = wc_attribute_label($attribute['name']);
                 }
             }
             if (empty($missing_attributes)) {
                 // Add to cart validation
                 $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $q, $variation_id, $variations);
                 if ($passed_validation) {
                     $added = WC()->cart->add_to_cart($product_id, $q, $variation_id, $variations);
                 }
             } else {
                 $failed_count++;
                 continue;
             }
             if ($added) {
                 $added_count++;
             } else {
                 $failed_count++;
             }
         }
     }
     if ($added_count) {
         woocommerce_bulk_variations_add_to_cart_message($added_count);
     }
     if ($failed_count) {
         WC_Bulk_Variations_Compatibility::wc_add_error(sprintf(__('Unable to add %s to the cart.  Please check your quantities and make sure the item is available and in stock', 'wc_bulk_variations'), $failed_count));
     }
     if (!$added_count && !$failed_count) {
         WC_Bulk_Variations_Compatibility::wc_add_error(__('No product quantities entered.', 'wc_bulk_variations'));
     }
     // If we added the products to the cart we can now do a redirect, otherwise just continue loading the page to show errors
     if ($failed_count === 0 && wc_notice_count('error') === 0) {
         // If has custom URL redirect there
         if ($url = apply_filters('woocommerce_add_to_cart_redirect', false)) {
             wp_safe_redirect($url);
             exit;
         } elseif (get_option('woocommerce_cart_redirect_after_add') === 'yes') {
             wp_safe_redirect(WC()->cart->get_cart_url());
             exit;
         }
     }
 }
function woocommerce_bulk_variations_add_to_cart_message($count)
{
    global $woocommerce;
    // Output success messages
    if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
        $return_to = wp_get_referer() ? wp_get_referer() : home_url();
        $message = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping &rarr;', 'wc_bulk_variations'), sprintf(__('%s products successfully added to your cart.', 'wc_bulk_variations'), $count));
    } else {
        $message = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), sprintf(__('%s products successfully added to your cart.', 'wc_bulk_variations'), $count));
    }
    WC_Bulk_Variations_Compatibility::wc_add_notice(apply_filters('woocommerce_bv_add_to_cart_message', $message));
}