Пример #1
1
function as_ajax_add_compare_product()
{
    $product_id = $_REQUEST["product_id"];
    $response = array("status" => 0, "message" => "something error");
    if (!empty($product_id) && is_numeric($product_id)) {
        $product = wc_get_product($product_id);
        if (!empty($product)) {
            $compare_product = as_get_product_compare();
            if (isset($compare_product[$product_id])) {
                $response["message"] = __("Product is in compare", AS_DOMAIN) . ' | <a target="_blank" href="' . get_page_link(get_option("as-compare-page-id")) . '">' . __("Go to compare", AS_DOMAIN) . '</a>';
            } else {
                $product_attrs = $product->get_attributes();
                $new_product_attrs = array();
                foreach ($product_attrs as $attribute) {
                    if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
                        continue;
                    } else {
                        if ($attribute['is_taxonomy']) {
                            $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
                            $values = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
                        } else {
                            // Convert pipes to commas and display values
                            $values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
                            $values = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
                        }
                        $data_attr = array("name" => $attribute["name"], "title" => wc_attribute_label($attribute['name']), "values" => $values);
                        $new_product_attrs[$attribute["name"]] = $data_attr;
                    }
                }
                $data_product = array("id" => $product_id, "name" => $product->get_title(), "price" => $product->get_price(), "image" => $product->get_image(), "attributes" => $new_product_attrs);
                as_save_product_compare($data_product);
                $response = array("status" => 1, "message" => "Success", "notice" => __("Product is in compare", AS_DOMAIN) . ' | <a target="_blank" href="' . get_page_link(get_option("as-compare-page-id")) . '">' . __("Go to compare", AS_DOMAIN) . '</a>');
            }
        } else {
            $response["message"] = __("Product does not existed", AS_DOMAIN);
        }
    } else {
        $response["message"] = __("Product does not true", AS_DOMAIN);
    }
    wp_send_json($response);
}
 static function addAttributeSetToProduct()
 {
     ob_start();
     global $wc_product_attributes;
     $attributeSetKey = $_POST['key'];
     $db = new WCAttributeSetsDb();
     $attributeSet = $db->get($attributeSetKey);
     if (empty($attributeSet->attributes)) {
         die;
     }
     foreach ($attributeSet->attributes as $attributeKey) {
         $thepostid = 0;
         $taxonomy = wc_attribute_taxonomy_name($attributeKey);
         $i = absint($_POST['i']);
         $position = 0;
         $metabox_class = array();
         $attribute = array('name' => $taxonomy, 'value' => '', 'is_visible' => apply_filters('woocommerce_attribute_default_visibility', 1), 'is_variation' => 0, 'is_taxonomy' => $taxonomy ? 1 : 0);
         if ($taxonomy) {
             $attribute_taxonomy = $wc_product_attributes[$taxonomy];
             $metabox_class[] = 'taxonomy';
             $metabox_class[] = $taxonomy;
             $attribute_label = wc_attribute_label($taxonomy);
         } else {
             $attribute_label = '';
         }
         include WC()->plugin_path() . '/includes/admin/meta-boxes/views/html-product-attribute.php';
     }
     die;
 }
 function get_item_data($other_data, $cart_item)
 {
     if (isset($cart_item["wpb_cart_items"])) {
         $wpb_cart_items = $cart_item["wpb_cart_items"];
         $other_data = array();
         $variation_data = $cart_item["variation"];
         if (!empty($variation_data)) {
             foreach ($variation_data as $attribute => $variation) {
                 $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($attribute)));
                 $term = get_term_by('slug', $variation, $taxonomy);
                 $attribute_type = WPB_Common_Functions::get_variation_attribute_type($taxonomy);
                 if ($attribute_type == "carousel") {
                     $other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $term->name, 'value' => '', 'hidden' => false);
                 }
                 if ($attribute_type == "extra") {
                     $extra_options = $wpb_cart_items["extra"];
                     $display_label = !empty($extra_options[$taxonomy]) ? $term->name . '(' . $extra_options[$taxonomy] . ')' : $term->name;
                     $other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $display_label, 'value' => '', 'hidden' => false);
                 }
                 if ($attribute_type == "size") {
                     $size_options = $wpb_cart_items["size"];
                     $display_label = !empty($size_options[$taxonomy]) ? $size_options[$taxonomy] : "";
                     $other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $display_label, 'value' => '', 'hidden' => false);
                 }
             }
         }
     }
     return $other_data;
 }
    /**
     * Get column value.
     *
     * @param mixed $item
     * @param string $column_name
     */
    public function column_default($item, $column_name)
    {
        global $product;
        if (!$product || $product->id !== $item->id) {
            $product = wc_get_product($item->id);
        }
        switch ($column_name) {
            case 'product':
                if ($sku = $product->get_sku()) {
                    echo $sku . ' - ';
                }
                echo $product->get_title();
                // Get variation data
                if ($product->is_type('variation')) {
                    $list_attributes = array();
                    $attributes = $product->get_variation_attributes();
                    foreach ($attributes as $name => $attribute) {
                        $list_attributes[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': <strong>' . $attribute . '</strong>';
                    }
                    echo '<div class="description">' . implode(', ', $list_attributes) . '</div>';
                }
                break;
            case 'parent':
                if ($item->parent) {
                    echo get_the_title($item->parent);
                } else {
                    echo '-';
                }
                break;
            case 'stock_status':
                if ($product->is_in_stock()) {
                    $stock_html = '<mark class="instock">' . __('In stock', 'woocommerce') . '</mark>';
                } else {
                    $stock_html = '<mark class="outofstock">' . __('Out of stock', 'woocommerce') . '</mark>';
                }
                echo apply_filters('woocommerce_admin_stock_html', $stock_html, $product);
                break;
            case 'stock_level':
                echo $product->get_stock_quantity();
                break;
            case 'wc_actions':
                ?>
<p>
					<?php 
                $actions = array();
                $action_id = $product->is_type('variation') ? $item->parent : $item->id;
                $actions['edit'] = array('url' => admin_url('post.php?post=' . $action_id . '&action=edit'), 'name' => __('Edit', 'woocommerce'), 'action' => "edit");
                if ($product->is_visible()) {
                    $actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'woocommerce'), 'action' => "view");
                }
                $actions = apply_filters('woocommerce_admin_stock_report_product_actions', $actions, $product);
                foreach ($actions as $action) {
                    printf('<a class="button tips %s" href="%s" data-tip="%s ' . __('product', 'woocommerce') . '">%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                }
                ?>
				</p><?php 
                break;
        }
    }
    /**
     * Display meta in a formatted list
     *
     * @access public
     * @param bool $flat (default: false)
     * @param bool $return (default: false)
     * @param string $hideprefix (default: _)
     * @return string
     */
    public function display($flat = false, $return = false, $hideprefix = '_')
    {
        if (!empty($this->meta)) {
            $meta_list = array();
            foreach ($this->meta as $meta_key => $meta_values) {
                if (empty($meta_values) || !empty($hideprefix) && substr($meta_key, 0, 1) == $hideprefix) {
                    continue;
                }
                foreach ($meta_values as $meta_value) {
                    // Skip serialised meta
                    if (is_serialized($meta_value)) {
                        continue;
                    }
                    $attribute_key = urldecode(str_replace('attribute_', '', $meta_key));
                    // If this is a term slug, get the term's nice name
                    if (taxonomy_exists($attribute_key)) {
                        $term = get_term_by('slug', $meta_value, $attribute_key);
                        if (!is_wp_error($term) && is_object($term) && $term->name) {
                            $meta_value = $term->name;
                        }
                        // If we have a product, and its not a term, try to find its non-sanitized name
                    } elseif ($this->product) {
                        $product_attributes = $this->product->get_attributes();
                        if (isset($product_attributes[$attribute_key])) {
                            $meta_key = wc_attribute_label($product_attributes[$attribute_key]['name']);
                        }
                    }
                    if ($flat) {
                        $meta_list[] = wp_kses_post(wc_attribute_label($attribute_key) . ': ' . apply_filters('woocommerce_order_item_display_meta_value', $meta_value));
                    } else {
                        $meta_list[] = '
							<dt class="variation-' . sanitize_html_class(sanitize_text_field($meta_key)) . '">' . wp_kses_post(wc_attribute_label($attribute_key)) . ':</dt>
							<dd class="variation-' . sanitize_html_class(sanitize_text_field($meta_key)) . '">' . wp_kses_post(wpautop(apply_filters('woocommerce_order_item_display_meta_value', $meta_value))) . '</dd>
						';
                    }
                }
            }
            if (!sizeof($meta_list)) {
                return '';
            }
            $output = $flat ? '' : '<dl class="variation">';
            if ($flat) {
                $output .= implode(", \n", $meta_list);
            } else {
                $output .= implode('', $meta_list);
            }
            if (!$flat) {
                $output .= '</dl>';
            }
            if ($return) {
                return $output;
            } else {
                echo $output;
            }
        }
        return '';
    }
 /**
  * Compatibility function for outputting a woocommerce attribute label
  *
  * @since 1.0
  * @param string $label the label to display
  * @return string the label to display
  */
 public static function wc_attribute_label($label)
 {
     if (self::is_wc_version_gte_2_1()) {
         return wc_attribute_label($label);
     } else {
         global $woocommerce;
         return $woocommerce->attribute_label($label);
     }
 }
Пример #7
0
 /**
  * Sort the data for CSV output first
  *
  * @param int   $product_id
  * @param array $headers
  * @param array $body
  * @param array $items
  */
 public static function output_csv($product_id, $headers, $body, $items)
 {
     $headers['quantity'] = __('Quantity', 'wcvendors');
     $new_body = array();
     foreach ($body as $i => $order) {
         // Remove comments
         unset($body[$i]['comments']);
         // Remove all numeric keys in each order (these are the meta values we are redoing into new lines)
         foreach ($order as $key => $col) {
             if (is_int($key)) {
                 unset($order[$key]);
             }
         }
         // New order row
         $new_row = $body[$i];
         // Remove order to redo
         unset($body[$i]);
         $order = new WC_Order($i);
         foreach ($items[$i]['items'] as $item) {
             $product_id = !empty($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
             $new_row_with_meta = $new_row;
             // Add the qty row
             $new_row_with_meta[] = $item['qty'];
             $item_meta = $item['name'];
             if ($metadata = $order->has_meta($item['product_id'])) {
                 foreach ($metadata as $meta) {
                     // Skip hidden core fields
                     if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array('_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', WC_Vendors::$pv_options->get_option('sold_by_label'))))) {
                         continue;
                     }
                     // Skip serialised meta
                     if (is_serialized($meta['meta_value'])) {
                         continue;
                     }
                     // Get attribute data
                     if (taxonomy_exists(wc_sanitize_taxonomy_name($meta['meta_key']))) {
                         $term = get_term_by('slug', $meta['meta_value'], wc_sanitize_taxonomy_name($meta['meta_key']));
                         $meta['meta_key'] = wc_attribute_label(wc_sanitize_taxonomy_name($meta['meta_key']));
                         $meta['meta_value'] = isset($term->name) ? $term->name : $meta['meta_value'];
                     } else {
                         $meta['meta_key'] = apply_filters('woocommerce_attribute_label', wc_attribute_label($meta['meta_key'], $_product), $meta['meta_key']);
                     }
                     $item_meta .= wp_kses_post(rawurldecode($meta['meta_key'])) . ':' . wp_kses_post(wpautop(make_clickable(rawurldecode($meta['meta_value']))));
                 }
             }
             $new_row_with_meta['product'] = $item_meta;
             $new_body[] = $new_row_with_meta;
         }
     }
     $headers = apply_filters('wcvendors_csv_headers', $headers, $product_id, $items);
     $body = apply_filters('wcvendors_csv_body', $new_body, $product_id, $items);
     WCV_Export_CSV::download($headers, $body, $product_id);
 }
 /**
  * Display meta in a formatted list
  *
  * @access public
  * @param bool $flat (default: false)
  * @param bool $return (default: false)
  * @param string $hideprefix (default: _)
  * @return string
  */
 public function display($flat = false, $return = false, $hideprefix = '_')
 {
     if (!empty($this->meta)) {
         $meta_list = array();
         foreach ($this->meta as $meta_key => $meta_values) {
             if (empty($meta_values) || !empty($hideprefix) && substr($meta_key, 0, 1) == $hideprefix) {
                 continue;
             }
             foreach ($meta_values as $meta_value) {
                 // Skip serialised meta
                 if (is_serialized($meta_value)) {
                     continue;
                 }
                 // If this is a term slug, get the term's nice name
                 if (taxonomy_exists(esc_attr(str_replace('attribute_', '', $meta_key)))) {
                     $term = get_term_by('slug', $meta_value, esc_attr(str_replace('attribute_', '', $meta_key)));
                     if (!is_wp_error($term) && $term->name) {
                         $meta_value = $term->name;
                     }
                 }
                 if ($flat) {
                     $meta_list[] = esc_attr(wc_attribute_label(str_replace('attribute_', '', $meta_key)) . ': ' . apply_filters('woocommerce_order_item_display_meta_value', $meta_value));
                 } else {
                     $meta_list[] = '<dt>' . wp_kses_post(wc_attribute_label(str_replace('attribute_', '', $meta_key))) . ':</dt><dd>' . wp_kses_post(wpautop(apply_filters('woocommerce_order_item_display_meta_value', $meta_value))) . '</dd>';
                 }
             }
         }
         if (!sizeof($meta_list)) {
             return '';
         }
         $output = $flat ? '' : '<dl class="variation">';
         if ($flat) {
             $output .= implode(", \n", $meta_list);
         } else {
             $output .= implode('', $meta_list);
         }
         if (!$flat) {
             $output .= '</dl>';
         }
         if ($return) {
             return $output;
         } else {
             echo $output;
         }
     }
     return '';
 }
 private function get_cart_item_data($cart_item)
 {
     $item_data = array();
     // Variation data
     if (!empty($cart_item['data']->variation_id) && is_array($cart_item['variation'])) {
         foreach ($cart_item['variation'] as $name => $value) {
             if ('' === $value) {
                 continue;
             }
             $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name)));
             // If this is a term slug, get the term's nice name
             if (taxonomy_exists($taxonomy)) {
                 $term = get_term_by('slug', $value, $taxonomy);
                 if (!is_wp_error($term) && $term && $term->name) {
                     $value = $term->name;
                 }
                 $label = wc_attribute_label($taxonomy);
                 // If this is a custom option slug, get the options name
             } else {
                 $value = apply_filters('woocommerce_variation_option_name', $value);
                 $product_attributes = $cart_item['data']->get_attributes();
                 if (isset($product_attributes[str_replace('attribute_', '', $name)])) {
                     $label = wc_attribute_label($product_attributes[str_replace('attribute_', '', $name)]['name']);
                 } else {
                     $label = $name;
                 }
             }
             $item_data[] = array('key' => $label, 'value' => $value);
         }
     }
     // Filter item data to allow 3rd parties to add more to the array
     $item_data = apply_filters('woocommerce_get_item_data', $item_data, $cart_item);
     // Format item data ready to display
     foreach ($item_data as $key => $data) {
         // Set hidden to true to not display meta on cart.
         if (!empty($data['hidden'])) {
             unset($item_data[$key]);
             continue;
         }
         $item_data[$key]['key'] = !empty($data['key']) ? $data['key'] : $data['name'];
         $item_data[$key]['display'] = !empty($data['display']) ? $data['display'] : $data['value'];
     }
     return $item_data;
 }
/**
 * 
 * @param type $cart_item
 * @param type $flat
 * @return string
 */
function wb_get_item_data($cart_item, $flat = false)
{
    $item_data = array();
    if (!empty($cart_item['data']->variation_id) && is_array($cart_item['variation'])) {
        foreach ($cart_item['variation'] as $name => $value) {
            if ('' === $value) {
                continue;
            }
            $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name)));
            if (taxonomy_exists($taxonomy)) {
                $term = get_term_by('slug', $value, $taxonomy);
                if (!is_wp_error($term) && $term && $term->name) {
                    $value = $term->name;
                }
                $label = wc_attribute_label($taxonomy);
            } else {
                $value = apply_filters('woocommerce_variation_option_name', $value);
                $product_attributes = $cart_item['data']->get_attributes();
                if (isset($product_attributes[str_replace('attribute_', '', $name)])) {
                    $label = wc_attribute_label($product_attributes[str_replace('attribute_', '', $name)]['name']);
                } else {
                    $label = $name;
                }
            }
            $item_data[] = array('key' => $label, 'value' => $value);
        }
    }
    $other_data = apply_filters('woocommerce_get_item_data', array(), $cart_item);
    if ($other_data && is_array($other_data) && sizeof($other_data) > 0) {
        foreach ($other_data as $data) {
            if (empty($data['hidden'])) {
                $display_value = !empty($data['display']) ? $data['display'] : $data['value'];
                $item_data[] = array('key' => $data['name'], 'value' => $display_value);
            }
        }
    }
    if (sizeof($item_data) > 0) {
        return $item_data;
    }
    return '';
}
 /**
  * wcj_get_order_item_meta_info.
  *
  * from woocommerce\includes\admin\meta-boxes\views\html-order-item-meta.php
  *
  * @version 2.5.9
  * @since   2.5.9
  */
 function wcj_get_order_item_meta_info($item_id, $item, $_order, $exclude_wcj_meta = false, $_product = null)
 {
     $meta_info = '';
     if ($metadata = $_order->has_meta($item_id)) {
         $meta_info = array();
         foreach ($metadata as $meta) {
             // Skip hidden core fields
             if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array('_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', 'method_id', 'cost')))) {
                 continue;
             }
             if ($exclude_wcj_meta && ('wcj' === substr($meta['meta_key'], 0, 3) || '_wcj' === substr($meta['meta_key'], 0, 4))) {
                 continue;
             }
             // Skip serialised meta
             if (is_serialized($meta['meta_value'])) {
                 continue;
             }
             // Get attribute data
             if (taxonomy_exists(wc_sanitize_taxonomy_name($meta['meta_key']))) {
                 $term = get_term_by('slug', $meta['meta_value'], wc_sanitize_taxonomy_name($meta['meta_key']));
                 $meta['meta_key'] = wc_attribute_label(wc_sanitize_taxonomy_name($meta['meta_key']));
                 $meta['meta_value'] = isset($term->name) ? $term->name : $meta['meta_value'];
             } else {
                 $the_product = null;
                 if (is_object($_product)) {
                     $the_product = $_product;
                 } elseif (is_object($item)) {
                     $the_product = $_order->get_product_from_item($item);
                 }
                 $meta['meta_key'] = is_object($the_product) ? wc_attribute_label($meta['meta_key'], $the_product) : $meta['meta_key'];
             }
             $meta_info[] = wp_kses_post(rawurldecode($meta['meta_key'])) . ': ' . wp_kses_post(rawurldecode($meta['meta_value']));
         }
         $meta_info = implode(', ', $meta_info);
     }
     return $meta_info;
 }
 /**
  * Handle adding variable products to the cart
  * @since 2.4.6 Split from add_to_cart_action
  * @param int $product_id
  * @return bool success or not
  */
 private static function add_to_cart_handler_variable($product_id)
 {
     $adding_to_cart = wc_get_product($product_id);
     $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
     $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
     $missing_attributes = array();
     $variations = array();
     $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($_REQUEST[$taxonomy])) {
             // Get value from post data
             if ($attribute['is_taxonomy']) {
                 // Don't use wc_clean as it destroys sanitized characters
                 $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
             } else {
                 $value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
             }
             // Get valid value from variation
             $valid_value = $variation->variation_data[$taxonomy];
             // Allow if valid
             if ('' === $valid_value || $valid_value === $value) {
                 $variations[$taxonomy] = $value;
                 continue;
             }
         } else {
             $missing_attributes[] = wc_attribute_label($attribute['name']);
         }
     }
     if ($missing_attributes) {
         wc_add_notice(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)), 'error');
     } elseif (empty($variation_id)) {
         wc_add_notice(__('Please choose product options&hellip;', 'woocommerce'), 'error');
     } else {
         // Add to cart validation
         $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations);
         if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations) !== false) {
             wc_add_to_cart_message($product_id);
             return true;
         }
     }
     return false;
 }
 /**
  * Validates that all composited items chosen can be added-to-cart before actually starting to add items.
  *
  * @param  bool 	$add
  * @param  int 		$product_id
  * @param  int 		$product_quantity
  * @return bool
  */
 public function wc_cp_validation($add, $product_id, $product_quantity, $variation_id = '', $variations = array(), $cart_item_data = array())
 {
     // Get product type
     $terms = get_the_terms($product_id, 'product_type');
     $product_type = !empty($terms) && isset(current($terms)->name) ? sanitize_title(current($terms)->name) : 'simple';
     // Ordering again?
     $order_again = isset($_GET['order_again']) && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce-order_again');
     // prevent composited items from getting validated - they will be added by the container item.
     if (isset($cart_item_data['is_composited']) && $order_again) {
         return false;
     }
     if ($product_type == 'composite') {
         // Get composite data
         $composite = wc_get_product($product_id);
         $composite_data = $composite->get_composite_data();
         $component_ids = array_keys($composite_data);
         // Check request and prepare validation data for stock and scenarios.
         $validate_scenarios = array();
         // If a stock-managed product / variation exists in the bundle multiple times, its stock will be checked only once for the sum of all bundled quantities.
         // The WC_CP_Stock_Manager class does exactly that
         $composited_stock = new WC_CP_Stock_Manager($composite);
         foreach ($component_ids as $component_id) {
             // Check that a product has been selected
             if (isset($_REQUEST['wccp_component_selection'][$component_id]) && $_REQUEST['wccp_component_selection'][$component_id] !== '') {
                 $composited_product_id = $_REQUEST['wccp_component_selection'][$component_id];
             } elseif (isset($cart_item_data['composite_data'][$component_id]['product_id']) && $order_again) {
                 $composited_product_id = $cart_item_data['composite_data'][$component_id]['product_id'];
             } else {
                 $_REQUEST['wccp_component_selection'][$component_id] = '';
                 // Save for later
                 $validate_scenarios[$component_id] = array();
                 $validate_scenarios[$component_id]['product_id'] = '0';
                 $validate_scenarios[$component_id]['product_type'] = 'none';
                 continue;
             }
             // Prevent people from f*****g around - only valid component options can be added to the cart.
             if (!in_array($composited_product_id, WC_CP()->api->get_component_options($composite_data[$component_id]))) {
                 return false;
             }
             $item_quantity_min = absint($composite_data[$component_id]['quantity_min']);
             $item_quantity_max = $composite_data[$component_id]['quantity_max'] !== '' ? absint($composite_data[$component_id]['quantity_max']) : '';
             // Check quantity
             if (isset($_REQUEST['wccp_component_quantity'][$component_id]) && is_numeric($_REQUEST['wccp_component_quantity'][$component_id])) {
                 $item_quantity = absint($_REQUEST['wccp_component_quantity'][$component_id]);
             } elseif (isset($cart_item_data['composite_data'][$component_id]['quantity']) && $order_again) {
                 $item_quantity = absint($cart_item_data['composite_data'][$component_id]['quantity']);
             } else {
                 $item_quantity = $item_quantity_min;
             }
             $quantity = $item_quantity * $product_quantity;
             $item_sold_individually = get_post_meta($composited_product_id, '_sold_individually', true);
             if ($item_sold_individually === 'yes' && $quantity > 1) {
                 $quantity = 1;
             }
             // Save for later.
             $validate_scenarios[$component_id] = array();
             $validate_scenarios[$component_id]['quantity'] = $item_quantity;
             $validate_scenarios[$component_id]['quantity_min'] = $item_quantity_min;
             $validate_scenarios[$component_id]['quantity_max'] = $item_quantity_max;
             $validate_scenarios[$component_id]['sold_individually'] = $item_sold_individually;
             // Get composited product type.
             $composited_product_wrapper = $composite->get_composited_product($component_id, $composited_product_id);
             if (!$composited_product_wrapper) {
                 wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. Please choose another &quot;%2$s&quot; option&hellip;', 'woocommerce-composite-products'), get_the_title($product_id), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id)), 'error');
                 return false;
             }
             $composited_product = $composited_product_wrapper->get_product();
             $composited_product_type = $composited_product->product_type;
             // Save for later.
             $validate_scenarios[$component_id]['product_type'] = $composited_product_type;
             $validate_scenarios[$component_id]['product_id'] = $composited_product_id;
             // Validate attributes.
             if ($composited_product_type === 'variable') {
                 $variation_id = '';
                 if (isset($cart_item_data['composite_data'][$component_id]['variation_id']) && $order_again) {
                     $variation_id = $cart_item_data['composite_data'][$component_id]['variation_id'];
                 } elseif (isset($_REQUEST['wccp_variation_id'][$component_id])) {
                     $variation_id = $_REQUEST['wccp_variation_id'][$component_id];
                 }
                 if ($variation_id && is_numeric($variation_id) && $variation_id > 1) {
                     // Add item for validation.
                     $composited_stock->add_item($composited_product_id, $variation_id, $quantity);
                     // Save for later.
                     $validate_scenarios[$component_id]['variation_id'] = $variation_id;
                 }
                 // Verify all attributes for the variable product were set.
                 $composited_variation = wc_get_product($variation_id);
                 $attributes = $composited_product->get_attributes();
                 $variation_data = array();
                 $missing_attributes = array();
                 $all_set = true;
                 if ($composited_variation) {
                     $variation_data = $composited_variation->variation_data;
                 }
                 foreach ($attributes as $attribute) {
                     if (!$attribute['is_variation']) {
                         continue;
                     }
                     $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
                     if (isset($_REQUEST['wccp_' . $taxonomy][$component_id])) {
                         if (WC_CP_Core_Compatibility::is_wc_version_gte_2_4()) {
                             // Get value from post data.
                             if ($attribute['is_taxonomy']) {
                                 $value = sanitize_title(stripslashes($_REQUEST['wccp_' . $taxonomy][$component_id]));
                             } else {
                                 $value = wc_clean(stripslashes($_REQUEST['wccp_' . $taxonomy][$component_id]));
                             }
                         } else {
                             // Get value from post data.
                             $value = sanitize_title(trim(stripslashes($_REQUEST['wccp_' . $taxonomy][$component_id])));
                         }
                         // Get valid value from variation.
                         $valid_value = $variation_data[$taxonomy];
                         // Allow if valid.
                         if ($valid_value === '' || $valid_value === $value) {
                             continue;
                         }
                     } elseif (isset($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy]) && isset($cart_item_data['composite_data'][$component_id]['variation_id']) && $order_again) {
                         if (WC_CP_Core_Compatibility::is_wc_version_gte_2_4()) {
                             // Get value from post data.
                             if ($attribute['is_taxonomy']) {
                                 $value = sanitize_title(stripslashes($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy]));
                             } else {
                                 $value = wc_clean(stripslashes($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy]));
                             }
                         } else {
                             // Get value from post data.
                             $value = sanitize_title(trim(stripslashes($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy])));
                         }
                         $valid_value = $variation_data[$taxonomy];
                         if ($valid_value === '' || $valid_value === $value) {
                             continue;
                         }
                     } else {
                         $missing_attributes[] = wc_attribute_label($attribute['name']);
                     }
                     $all_set = false;
                 }
                 if (!$all_set) {
                     if ($missing_attributes && WC_CP_Core_Compatibility::is_wc_version_gte_2_3()) {
                         $required_fields_notice = sprintf(_n('%1$s is a required &quot;%2$s&quot; field', '%1$s are required &quot;%2$s&quot; fields', sizeof($missing_attributes), 'woocommerce-composite-products'), wc_format_list_of_items($missing_attributes), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id));
                         wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. %2$s.', 'woocommerce-composite-products'), get_the_title($product_id), $required_fields_notice), 'error');
                         return false;
                     } else {
                         wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. Please choose &quot;%2$s&quot; options&hellip;', 'woocommerce-composite-products'), get_the_title($product_id), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id)), 'error');
                         return false;
                     }
                 }
             } elseif ($composited_product_type === 'simple') {
                 // Add item for validation.
                 $composited_stock->add_item($composited_product_id, false, $quantity);
             } else {
                 // Add item for validation.
                 $composited_stock->add_item($composited_product_id, false, $quantity);
             }
             if (!apply_filters('woocommerce_composite_component_add_to_cart_validation', true, $product_id, $component_id, $composited_product_id, $quantity, $cart_item_data)) {
                 return false;
             }
             // Allow composited products to add extra items to the stock manager.
             $composited_stock->add_stock(apply_filters('woocommerce_composite_component_associated_stock', '', $product_id, $component_id, $composited_product_id, $quantity));
         }
         /*
          * Stock Validation.
          */
         if (false === $composited_stock->validate_stock()) {
             return false;
         }
         /*
          * Scenarios Validation.
          */
         $scenario_data = get_post_meta($product_id, '_bto_scenario_data', true);
         $scenario_data = apply_filters('woocommerce_composite_scenario_meta', $scenario_data, $composite);
         $posted_scenarios = !empty($_POST['wccp_active_scenarios']) ? array_map('wc_clean', explode(',', $_POST['wccp_active_scenarios'])) : array();
         if (!empty($posted_scenarios)) {
             $scenario_data = array_intersect_key($scenario_data, array_flip($posted_scenarios));
         }
         // Build scenarios for the selected combination of options
         foreach ($composite_data as $component_id => &$modified_component_data) {
             if (isset($validate_scenarios[$component_id]) && $validate_scenarios[$component_id]['product_type'] !== 'none') {
                 $modified_component_data['current_component_options'] = array($validate_scenarios[$component_id]['product_id']);
             } else {
                 $modified_component_data['current_component_options'] = array('');
             }
         }
         $scenarios_for_products = apply_filters('woocommerce_composite_validation_scenario_data', WC_CP_Scenarios::build_scenarios($scenario_data, $composite_data), $composite_data, $scenario_data, $product_id);
         $common_scenarios = array_values($scenarios_for_products['scenarios']);
         $common_compat_group_scenarios = WC_CP_Scenarios::filter_scenarios_by_type($common_scenarios, 'compat_group', $scenarios_for_products);
         // Validate Selections.
         foreach ($composite_data as $component_id => $component_data) {
             if (isset($validate_scenarios[$component_id])) {
                 $validate_product_id = isset($validate_scenarios[$component_id]['variation_id']) ? $validate_scenarios[$component_id]['variation_id'] : $validate_scenarios[$component_id]['product_id'];
                 $scenarios_for_product = array();
                 $mandatory_override_check = false;
                 if ($validate_product_id === '0' && $component_data['optional'] === 'no') {
                     $mandatory_override_check = true;
                 }
                 if (!empty($scenarios_for_products['scenario_data'][$component_id][$validate_product_id])) {
                     $scenarios_for_product = $scenarios_for_products['scenario_data'][$component_id][$validate_product_id];
                     $compat_group_scenarios_for_product = WC_CP_Scenarios::filter_scenarios_by_type($scenarios_for_product, 'compat_group', $scenarios_for_products);
                 }
                 if (empty($compat_group_scenarios_for_product) || $mandatory_override_check) {
                     if ($validate_product_id === '0') {
                         // Allow 3rd parties to override notices for empty selections in non-optional components conditionally through scenarios.
                         if (apply_filters('woocommerce_composite_validation_component_is_mandatory', true, $component_id, $validate_scenarios[$component_id], $common_scenarios, $scenarios_for_products, $product_id)) {
                             wc_add_notice(sprintf(__('Please select a &quot;%s&quot; option.', 'woocommerce-composite-products'), apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id)), 'error');
                             return false;
                         }
                     } else {
                         wc_add_notice(sprintf(__('Please select a different &quot;%s&quot; option &mdash; the selected product cannot be purchased at the moment.', 'woocommerce-composite-products'), apply_filters('woocommerce_composite_component_title', $component_data['title'], $component_id, $product_id)), 'error');
                         return false;
                     }
                 } else {
                     $common_scenarios = array_intersect($common_scenarios, $scenarios_for_product);
                     $common_compat_group_scenarios = array_intersect($common_compat_group_scenarios, $compat_group_scenarios_for_product);
                 }
             }
         }
         if (empty($common_compat_group_scenarios)) {
             wc_add_notice(__('The selected options cannot be purchased together. Please select a different configuration and try again.', 'woocommerce-composite-products'), 'error');
             return false;
         }
         // Validate Quantities.
         foreach ($composite_data as $component_id => $component_data) {
             if (!isset($validate_scenarios[$component_id]) || $validate_scenarios[$component_id]['product_type'] === 'none') {
                 continue;
             }
             $qty = $validate_scenarios[$component_id]['quantity'];
             // Allow 3rd parties to modify the min/max qty settings of a component conditionally through scenarios.
             $qty_min = absint(apply_filters('woocommerce_composite_validation_component_quantity_min', $component_data['quantity_min'], $component_id, $validate_scenarios[$component_id], $common_scenarios, $scenarios_for_products, $product_id));
             $qty_max = absint(apply_filters('woocommerce_composite_validation_component_quantity_max', $component_data['quantity_max'], $component_id, $validate_scenarios[$component_id], $common_scenarios, $scenarios_for_products, $product_id));
             $sold_individually = $validate_scenarios[$component_id]['sold_individually'];
             if ($qty < $qty_min && $sold_individually !== 'yes') {
                 wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. The quantity of &quot;%2$s&quot; cannot be lower than %3$d.', 'woocommerce-composite-products'), get_the_title($product_id), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id), $qty_min), 'error');
                 return false;
             } elseif ($qty_max && $qty > $qty_max) {
                 wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. The quantity of &quot;%2$s&quot; cannot be higher than %3$d.', 'woocommerce-composite-products'), get_the_title($product_id), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id), $qty_max), 'error');
                 return false;
             }
         }
         $add = apply_filters('woocommerce_add_to_cart_composite_validation', $add, $product_id, $composited_stock);
     }
     return $add;
 }
 function get_products_atts()
 {
     $total_products = 0;
     $products_attributes = array();
     $attributes_names = array();
     $attributes_names['wcj_title'] = __('Product', 'woocommerce-jetpack');
     $attributes_names['wcj_category'] = __('Category', 'woocommerce-jetpack');
     $offset = 0;
     $block_size = 96;
     while (true) {
         $args_products = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $block_size, 'orderby' => 'title', 'order' => 'ASC', 'offset' => $offset);
         $loop_products = new WP_Query($args_products);
         if (!$loop_products->have_posts()) {
             break;
         }
         while ($loop_products->have_posts()) {
             $loop_products->the_post();
             $total_products++;
             $product_id = $loop_products->post->ID;
             $the_product = wc_get_product($product_id);
             $products_attributes[$product_id]['wcj_title'] = '<a href="' . get_permalink($product_id) . '">' . $the_product->get_title() . '</a>';
             $products_attributes[$product_id]['wcj_category'] = $the_product->get_categories();
             foreach ($the_product->get_attributes() as $attribute) {
                 $products_attributes[$product_id][$attribute['name']] = $the_product->get_attribute($attribute['name']);
                 if (!isset($attributes_names[$attribute['name']])) {
                     $attributes_names[$attribute['name']] = wc_attribute_label($attribute['name']);
                 }
             }
         }
         $offset += $block_size;
     }
     $table_data = array();
     if (isset($_GET['wcj_attribute']) && '' != $_GET['wcj_attribute']) {
         $table_data[] = array(__('Product', 'woocommerce-jetpack'), __('Category', 'woocommerce-jetpack'), $_GET['wcj_attribute']);
     } else {
         //			$table_data[] = array_values( $attributes_names );
         $table_data[] = array_keys($attributes_names);
     }
     foreach ($attributes_names as $attributes_name => $attribute_title) {
         if (isset($_GET['wcj_attribute']) && '' != $_GET['wcj_attribute']) {
             if ('wcj_title' != $attributes_name && 'wcj_category' != $attributes_name && $_GET['wcj_attribute'] != $attributes_name) {
                 continue;
             }
         }
         foreach ($products_attributes as $product_id => $product_attributes) {
             $table_data[$product_id][$attributes_name] = isset($product_attributes[$attributes_name]) ? $product_attributes[$attributes_name] : '';
         }
     }
     return '<p>' . __('Total Products:', 'woocommerce-jetpack') . ' ' . $total_products . '</p>' . wcj_get_table_html($table_data, array('table_class' => 'widefat striped'));
 }
 /**
  * Get the attributes for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_attributes($product)
 {
     $attributes = array();
     if ($product->is_type('variation')) {
         // variation attributes
         foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
             // taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
             $attributes[] = array('name' => wc_attribute_label(str_replace('attribute_', '', $attribute_name)), 'slug' => str_replace('attribute_', '', str_replace('pa_', '', $attribute_name)), 'option' => $attribute);
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             // taxonomy-based attributes are comma-separated, others are pipe (|) separated
             if ($attribute['is_taxonomy']) {
                 $options = explode(',', $product->get_attribute($attribute['name']));
             } else {
                 $options = explode('|', $product->get_attribute($attribute['name']));
             }
             $attributes[] = array('name' => wc_attribute_label($attribute['name']), 'slug' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', $options));
         }
     }
     return $attributes;
 }
            ?>
</div>
							</li>
							<?php 
        }
    }
    foreach ($product->get_attributes() as $attribute) {
        if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
            continue;
        } else {
            $show = true;
        }
        ?>
						<li class="clearfix">
							<div class="halfcol left"><?php 
        echo wc_attribute_label($attribute['name']);
        ?>
</div>
							<div class="halfcol right">
							<?php 
        if ($attribute['is_taxonomy']) {
            $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
            echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
        } else {
            $values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
            echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
        }
        ?>
							</div>
						</li>
						<?php 
    /**
     * Show options for the variable product type
     */
    public static function output_variations()
    {
        global $post;
        $attributes = maybe_unserialize(get_post_meta($post->ID, '_product_attributes', true));
        // See if any are set
        $variation_attribute_found = false;
        if ($attributes) {
            foreach ($attributes as $attribute) {
                if (isset($attribute['is_variation'])) {
                    $variation_attribute_found = true;
                    break;
                }
            }
        }
        // Get tax classes
        $tax_classes = WC_Tax::get_tax_classes();
        $tax_class_options = array();
        $tax_class_options[''] = __('Standard', 'woocommerce');
        if ($tax_classes) {
            foreach ($tax_classes as $class) {
                $tax_class_options[sanitize_title($class)] = esc_attr($class);
            }
        }
        $backorder_options = array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce'));
        $stock_status_options = array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce'));
        ?>
		<div id="variable_product_options" class="panel wc-metaboxes-wrapper"><div id="variable_product_options_inner">

			<?php 
        if (!$variation_attribute_found) {
            ?>

				<div id="message" class="inline woocommerce-message">
					<p><?php 
            _e('Before adding variations, add and save some attributes on the <strong>Attributes</strong> tab.', 'woocommerce');
            ?>
</p>

					<p class="submit"><a class="button-primary" href="<?php 
            echo esc_url(apply_filters('woocommerce_docs_url', 'http://docs.woothemes.com/document/variable-product/', 'product-variations'));
            ?>
" target="_blank"><?php 
            _e('Learn more', 'woocommerce');
            ?>
</a></p>
				</div>

			<?php 
        } else {
            ?>

				<p class="toolbar">
					<a href="#" class="close_all"><?php 
            _e('Close all', 'woocommerce');
            ?>
</a><a href="#" class="expand_all"><?php 
            _e('Expand all', 'woocommerce');
            ?>
</a>
					<select id="field_to_edit">
						<option value=""><?php 
            _e('Choose a field to bulk edit&hellip;', 'woocommerce');
            ?>
</option>
						<optgroup label="<?php 
            esc_attr_e('Status', 'woocommerce');
            ?>
">
							<option value="toggle_enabled"><?php 
            _e('Toggle &quot;Enabled&quot;', 'woocommerce');
            ?>
</option>
							<option value="toggle_downloadable"><?php 
            _e('Toggle &quot;Downloadable&quot;', 'woocommerce');
            ?>
</option>
							<option value="toggle_virtual"><?php 
            _e('Toggle &quot;Virtual&quot;', 'woocommerce');
            ?>
</option>
							<option value="delete_all"><?php 
            _e('Delete all variations', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Pricing', 'woocommerce');
            ?>
">
							<option value="variable_regular_price"><?php 
            _e('Prices', 'woocommerce');
            ?>
</option>
							<option value="variable_regular_price_increase"><?php 
            _e('Prices increase by (fixed amount or %)', 'woocommerce');
            ?>
</option>
							<option value="variable_regular_price_decrease"><?php 
            _e('Prices decrease by (fixed amount or %)', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_price"><?php 
            _e('Sale prices', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_price_increase"><?php 
            _e('Sale prices increase by (fixed amount or %)', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_price_decrease"><?php 
            _e('Sale prices decrease by (fixed amount or %)', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_schedule"><?php 
            _e('Scheduled sale dates', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Inventory', 'woocommerce');
            ?>
">
							<option value="toggle_manage_stock"><?php 
            _e('Toggle &quot;Manage stock&quot;', 'woocommerce');
            ?>
</option>
							<option value="variable_stock"><?php 
            _e('Stock', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Shipping', 'woocommerce');
            ?>
">
							<option value="variable_length"><?php 
            _e('Length', 'woocommerce');
            ?>
</option>
							<option value="variable_width"><?php 
            _e('Width', 'woocommerce');
            ?>
</option>
							<option value="variable_height"><?php 
            _e('Height', 'woocommerce');
            ?>
</option>
							<option value="variable_weight"><?php 
            _e('Weight', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Downloadable products', 'woocommerce');
            ?>
">
							<option value="variable_download_limit"><?php 
            _e('Download limit', 'woocommerce');
            ?>
</option>
							<option value="variable_download_expiry"><?php 
            _e('Download Expiry', 'woocommerce');
            ?>
</option>
						</optgroup>
						<?php 
            do_action('woocommerce_variable_product_bulk_edit_actions');
            ?>
					</select>
					<a class="button bulk_edit"><?php 
            _e('Go', 'woocommerce');
            ?>
</a>
				</p>

				<div class="woocommerce_variations wc-metaboxes">
					<?php 
            // Get parent data
            $parent_data = array('id' => $post->ID, 'attributes' => $attributes, 'tax_class_options' => $tax_class_options, 'sku' => get_post_meta($post->ID, '_sku', true), 'weight' => wc_format_localized_decimal(get_post_meta($post->ID, '_weight', true)), 'length' => wc_format_localized_decimal(get_post_meta($post->ID, '_length', true)), 'width' => wc_format_localized_decimal(get_post_meta($post->ID, '_width', true)), 'height' => wc_format_localized_decimal(get_post_meta($post->ID, '_height', true)), 'tax_class' => get_post_meta($post->ID, '_tax_class', true), 'backorder_options' => $backorder_options, 'stock_status_options' => $stock_status_options);
            if (!$parent_data['weight']) {
                $parent_data['weight'] = wc_format_localized_decimal(0);
            }
            if (!$parent_data['length']) {
                $parent_data['length'] = wc_format_localized_decimal(0);
            }
            if (!$parent_data['width']) {
                $parent_data['width'] = wc_format_localized_decimal(0);
            }
            if (!$parent_data['height']) {
                $parent_data['height'] = wc_format_localized_decimal(0);
            }
            // Get variations
            $args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID);
            $variations = get_posts($args);
            $loop = 0;
            if ($variations) {
                foreach ($variations as $variation) {
                    $variation_id = absint($variation->ID);
                    $variation_meta = get_post_meta($variation_id);
                    $variation_data = array();
                    $shipping_classes = get_the_terms($variation_id, 'product_shipping_class');
                    $variation_fields = array('_sku' => '', '_stock' => '', '_regular_price' => '', '_sale_price' => '', '_weight' => '', '_length' => '', '_width' => '', '_height' => '', '_download_limit' => '', '_download_expiry' => '', '_downloadable_files' => '', '_downloadable' => '', '_virtual' => '', '_thumbnail_id' => '', '_sale_price_dates_from' => '', '_sale_price_dates_to' => '', '_manage_stock' => '', '_stock_status' => '', '_backorders' => null, '_tax_class' => null);
                    foreach ($variation_fields as $field => $value) {
                        $variation_data[$field] = isset($variation_meta[$field][0]) ? maybe_unserialize($variation_meta[$field][0]) : $value;
                    }
                    // Add the variation attributes
                    foreach ($variation_meta as $key => $value) {
                        if (false !== strpos($key, 'attribute_')) {
                            $variation_data[$key] = $value;
                        }
                    }
                    // Formatting
                    $variation_data['_regular_price'] = wc_format_localized_price($variation_data['_regular_price']);
                    $variation_data['_sale_price'] = wc_format_localized_price($variation_data['_sale_price']);
                    $variation_data['_weight'] = wc_format_localized_decimal($variation_data['_weight']);
                    $variation_data['_length'] = wc_format_localized_decimal($variation_data['_length']);
                    $variation_data['_width'] = wc_format_localized_decimal($variation_data['_width']);
                    $variation_data['_height'] = wc_format_localized_decimal($variation_data['_height']);
                    $variation_data['_thumbnail_id'] = absint($variation_data['_thumbnail_id']);
                    $variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url($variation_data['_thumbnail_id']) : '';
                    $variation_data['shipping_class'] = $shipping_classes && !is_wp_error($shipping_classes) ? current($shipping_classes)->term_id : '';
                    // Stock BW compat
                    if ('' !== $variation_data['_stock']) {
                        $variation_data['_manage_stock'] = 'yes';
                    }
                    include 'views/html-variation-admin.php';
                    $loop++;
                }
            }
            ?>
				</div>

				<p class="toolbar">

					<button type="button" class="button button-primary add_variation" <?php 
            disabled($variation_attribute_found, false);
            ?>
><?php 
            _e('Add Variation', 'woocommerce');
            ?>
</button>

					<button type="button" class="button link_all_variations" <?php 
            disabled($variation_attribute_found, false);
            ?>
><?php 
            _e('Link all variations', 'woocommerce');
            ?>
</button>

					<strong><?php 
            _e('Defaults', 'woocommerce');
            ?>
: <span class="tips" data-tip="<?php 
            _e('These are the attributes that will be pre-selected on the frontend.', 'woocommerce');
            ?>
">[?]</span></strong>
					<?php 
            $default_attributes = maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true));
            foreach ($attributes as $attribute) {
                // Only deal with attributes that are variations
                if (!$attribute['is_variation']) {
                    continue;
                }
                // Get current value for variation (if set)
                $variation_selected_value = isset($default_attributes[sanitize_title($attribute['name'])]) ? $default_attributes[sanitize_title($attribute['name'])] : '';
                // Name will be something like attribute_pa_color
                echo '<select name="default_attribute_' . sanitize_title($attribute['name']) . '"><option value="">' . __('No default', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '&hellip;</option>';
                // Get terms for attribute taxonomy or value if its a custom attribute
                if ($attribute['is_taxonomy']) {
                    $post_terms = wp_get_post_terms($post->ID, $attribute['name']);
                    foreach ($post_terms as $term) {
                        echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>';
                    }
                } else {
                    $options = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
                    foreach ($options as $option) {
                        echo '<option ' . selected(sanitize_title($variation_selected_value), sanitize_title($option), false) . ' value="' . esc_attr(sanitize_title($option)) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
                    }
                }
                echo '</select>';
            }
            ?>
				</p>

			<?php 
        }
        ?>
		</div></div>
		<?php 
    }
 /**
  * Add to cart action
  *
  * Checks for a valid request, does validation (via hooks) and then redirects if valid.
  *
  * @param bool $url (default: false)
  */
 public static function add_to_cart_action($url = false)
 {
     if (empty($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) {
         return;
     }
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_REQUEST['add-to-cart']));
     $was_added_to_cart = false;
     $added_to_cart = array();
     $adding_to_cart = wc_get_product($product_id);
     $add_to_cart_handler = apply_filters('woocommerce_add_to_cart_handler', $adding_to_cart->product_type, $adding_to_cart);
     // Check if the product is published
     if ('publish' !== $adding_to_cart->post->post_status) {
         wc_add_notice(__('Sorry, this product is unavailable.', 'woocommerce'), 'error');
         return;
     }
     // Variable product handling
     if ('variable' === $add_to_cart_handler) {
         $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
         $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
         $missing_attributes = array();
         $variations = array();
         $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($_REQUEST[$taxonomy])) {
                 // Get value from post data
                 if ($attribute['is_taxonomy']) {
                     // Don't use wc_clean as it destroys sanitized characters
                     $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
                 } else {
                     $value = wc_clean(stripslashes($_REQUEST[$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 ($missing_attributes) {
             wc_add_notice(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)), 'error');
             return;
         } elseif (empty($variation_id)) {
             wc_add_notice(__('Please choose product options&hellip;', 'woocommerce'), 'error');
             return;
         } else {
             // Add to cart validation
             $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations);
             if ($passed_validation) {
                 if (WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations) !== false) {
                     wc_add_to_cart_message($product_id);
                     $was_added_to_cart = true;
                     $added_to_cart[] = $product_id;
                 }
             }
         }
         // Grouped Products
     } elseif ('grouped' === $add_to_cart_handler) {
         if (!empty($_REQUEST['quantity']) && is_array($_REQUEST['quantity'])) {
             $quantity_set = false;
             foreach ($_REQUEST['quantity'] as $item => $quantity) {
                 if ($quantity <= 0) {
                     continue;
                 }
                 $quantity_set = true;
                 // Add to cart validation
                 $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $item, $quantity);
                 if ($passed_validation) {
                     if (WC()->cart->add_to_cart($item, $quantity) !== false) {
                         $was_added_to_cart = true;
                         $added_to_cart[] = $item;
                     }
                 }
             }
             if ($was_added_to_cart) {
                 wc_add_to_cart_message($added_to_cart);
             }
             if (!$was_added_to_cart && !$quantity_set) {
                 wc_add_notice(__('Please choose the quantity of items you wish to add to your cart&hellip;', 'woocommerce'), 'error');
                 return;
             }
         } elseif ($product_id) {
             /* Link on product archives */
             wc_add_notice(__('Please choose a product to add to your cart&hellip;', 'woocommerce'), 'error');
             return;
         }
         // Custom Handler
     } elseif (has_action('woocommerce_add_to_cart_handler_' . $add_to_cart_handler)) {
         do_action('woocommerce_add_to_cart_handler_' . $add_to_cart_handler, $url);
         return;
         // Simple Products
     } else {
         $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
         // Add to cart validation
         $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
         if ($passed_validation) {
             // Add the product to the cart
             if (WC()->cart->add_to_cart($product_id, $quantity) !== false) {
                 wc_add_to_cart_message($product_id);
                 $was_added_to_cart = true;
                 $added_to_cart[] = $product_id;
             }
         }
     }
     // If we added the product to the cart we can now optionally do a redirect.
     if ($was_added_to_cart && wc_notice_count('error') == 0) {
         $url = apply_filters('woocommerce_add_to_cart_redirect', $url);
         // If has custom URL redirect there
         if ($url) {
             wp_safe_redirect($url);
             exit;
         } elseif (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
             wp_safe_redirect(WC()->cart->get_cart_url());
             exit;
         }
     }
 }
 /**
  * Handle adding variable products to the cart.
  * @since 2.4.6 Split from add_to_cart_action
  * @param int $product_id
  * @return bool success or not
  */
 private static function add_to_cart_handler_variable($product_id)
 {
     $adding_to_cart = wc_get_product($product_id);
     $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
     $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
     $missing_attributes = array();
     $variations = array();
     $attributes = $adding_to_cart->get_attributes();
     // If no variation ID is set, attempt to get a variation ID from posted attributes.
     if (empty($variation_id)) {
         $variation_id = $adding_to_cart->get_matching_variation(wp_unslash($_POST));
     }
     $variation = wc_get_product($variation_id);
     // Validate the attributes.
     try {
         if (empty($variation_id)) {
             throw new Exception(__('Please choose product options&hellip;', 'woocommerce'));
         }
         foreach ($attributes as $attribute) {
             if (!$attribute['is_variation']) {
                 continue;
             }
             $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
             if (isset($_REQUEST[$taxonomy])) {
                 // Get value from post data
                 if ($attribute['is_taxonomy']) {
                     // Don't use wc_clean as it destroys sanitized characters
                     $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
                 } else {
                     $value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
                 }
                 // Get valid value from variation
                 $valid_value = isset($variation->variation_data[$taxonomy]) ? $variation->variation_data[$taxonomy] : '';
                 // Allow if valid or show error.
                 if ('' === $valid_value || $valid_value === $value) {
                     $variations[$taxonomy] = $value;
                 } else {
                     throw new Exception(sprintf(__('Invalid value posted for %s', 'woocommerce'), wc_attribute_label($attribute['name'])));
                 }
             } else {
                 $missing_attributes[] = wc_attribute_label($attribute['name']);
             }
         }
         if (!empty($missing_attributes)) {
             throw new Exception(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)));
         }
     } catch (Exception $e) {
         wc_add_notice($e->getMessage(), 'error');
         return false;
     }
     // Add to cart validation
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations) !== false) {
         wc_add_to_cart_message(array($product_id => $quantity), true);
         return true;
     }
     return false;
 }
Пример #20
0
	<?php 
if (!empty($available_variations)) {
    ?>
		<table class="variations" cellspacing="0">
			<tbody>
				<?php 
    $loop = 0;
    foreach ($attributes as $name => $options) {
        $loop++;
        ?>
					<tr>
						<td class="label"><label for="<?php 
        echo sanitize_title($name);
        ?>
"><?php 
        echo wc_attribute_label($name);
        ?>
</label></td>
						<td class="value"><select id="<?php 
        echo esc_attr(sanitize_title($name));
        ?>
" name="attribute_<?php 
        echo sanitize_title($name);
        ?>
">
							<option value=""><?php 
        echo __('Choose an option', 'woocommerce');
        ?>
&hellip;</option>
							<?php 
        if (is_array($options)) {
Пример #21
0
?>
"></div>
		<strong>#<?php 
echo esc_html($variation_id);
?>
 &mdash; </strong>
		<?php 
foreach ($parent_data['attributes'] as $attribute) {
    // Only deal with attributes that are variations
    if (!$attribute['is_variation']) {
        continue;
    }
    // Get current value for variation (if set)
    $variation_selected_value = isset($variation_data['attribute_' . sanitize_title($attribute['name'])][0]) ? $variation_data['attribute_' . sanitize_title($attribute['name'])][0] : '';
    // Name will be something like attribute_pa_color
    echo '<select name="attribute_' . sanitize_title($attribute['name']) . '[' . $loop . ']"><option value="">' . __('Any', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '&hellip;</option>';
    // Get terms for attribute taxonomy or value if its a custom attribute
    if ($attribute['is_taxonomy']) {
        $post_terms = wp_get_post_terms($parent_data['id'], $attribute['name']);
        foreach ($post_terms as $term) {
            echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>';
        }
    } else {
        $options = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
        foreach ($options as $option) {
            echo '<option ' . selected(sanitize_title($variation_selected_value), sanitize_title($option), false) . ' value="' . esc_attr(sanitize_title($option)) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
        }
    }
    echo '</select>';
}
?>
Пример #22
0
 /**
  * Gets and formats a list of cart item data + variations for display on the frontend.
  *
  * @param array $cart_item
  * @param bool $flat (default: false)
  * @return string
  */
 public function get_item_data($cart_item, $flat = false)
 {
     $item_data = array();
     // Variation data
     if (!empty($cart_item['data']->variation_id) && is_array($cart_item['variation'])) {
         foreach ($cart_item['variation'] as $name => $value) {
             if ('' === $value) {
                 continue;
             }
             $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name)));
             // If this is a term slug, get the term's nice name
             if (taxonomy_exists($taxonomy)) {
                 $term = get_term_by('slug', $value, $taxonomy);
                 if (!is_wp_error($term) && $term && $term->name) {
                     $value = $term->name;
                 }
                 $label = wc_attribute_label($taxonomy);
                 // If this is a custom option slug, get the options name
             } else {
                 $value = apply_filters('woocommerce_variation_option_name', $value);
                 $product_attributes = $cart_item['data']->get_attributes();
                 if (isset($product_attributes[str_replace('attribute_', '', $name)])) {
                     $label = wc_attribute_label($product_attributes[str_replace('attribute_', '', $name)]['name']);
                 } else {
                     $label = $name;
                 }
             }
             $item_data[] = array('key' => $label, 'value' => $value);
         }
     }
     // Filter item data to allow 3rd parties to add more to the array
     $item_data = apply_filters('woocommerce_get_item_data', $item_data, $cart_item);
     // Format item data ready to display
     foreach ($item_data as $key => $data) {
         // Set hidden to true to not display meta on cart.
         if (!empty($data['hidden'])) {
             unset($item_data[$key]);
             continue;
         }
         $item_data[$key]['key'] = !empty($data['key']) ? $data['key'] : $data['name'];
         $item_data[$key]['display'] = !empty($data['display']) ? $data['display'] : $data['value'];
     }
     // Output flat or in list format
     if (sizeof($item_data) > 0) {
         ob_start();
         if ($flat) {
             foreach ($item_data as $data) {
                 echo esc_html($data['key']) . ': ' . wp_kses_post($data['display']) . "\n";
             }
         } else {
             wc_get_template('cart/cart-item-data.php', array('item_data' => $item_data));
         }
         return ob_get_clean();
     }
     return '';
 }
    /**
     * Show options for the variable product type
     */
    public static function output_variations()
    {
        global $post, $wpdb;
        // Get attributes
        $attributes = maybe_unserialize(get_post_meta($post->ID, '_product_attributes', true));
        // See if any are set
        $variation_attribute_found = false;
        if ($attributes) {
            foreach ($attributes as $attribute) {
                if (isset($attribute['is_variation'])) {
                    $variation_attribute_found = true;
                    break;
                }
            }
        }
        $variations_count = absint($wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = 'product_variation'", $post->ID)));
        $variations_per_page = absint(apply_filters('woocommerce_admin_meta_boxes_variations_per_page', 10));
        $variations_total_pages = ceil($variations_count / $variations_per_page);
        ?>
		<div id="variable_product_options" class="panel wc-metaboxes-wrapper"><div id="variable_product_options_inner">

			<?php 
        if (!$variation_attribute_found) {
            ?>

				<div id="message" class="inline woocommerce-message">
					<p><?php 
            _e('Before adding variations, add and save some attributes on the <strong>Attributes</strong> tab.', 'woocommerce');
            ?>
</p>

					<p class="submit"><a class="button-primary" href="<?php 
            echo esc_url(apply_filters('woocommerce_docs_url', 'http://docs.woothemes.com/document/variable-product/', 'product-variations'));
            ?>
" target="_blank"><?php 
            _e('Learn more', 'woocommerce');
            ?>
</a></p>
				</div>

			<?php 
        } else {
            ?>

				<div class="toolbar toolbar-variations-defaults">
					<div class="variations-defaults">
						<strong><?php 
            _e('Default Form Values', 'woocommerce');
            ?>
: <span class="tips" data-tip="<?php 
            _e('These are the attributes that will be pre-selected on the frontend.', 'woocommerce');
            ?>
">[?]</span></strong>
						<?php 
            $default_attributes = maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true));
            foreach ($attributes as $attribute) {
                // Only deal with attributes that are variations
                if (!$attribute['is_variation']) {
                    continue;
                }
                // Get current value for variation (if set)
                $variation_selected_value = isset($default_attributes[sanitize_title($attribute['name'])]) ? $default_attributes[sanitize_title($attribute['name'])] : '';
                // Name will be something like attribute_pa_color
                echo '<select name="default_attribute_' . sanitize_title($attribute['name']) . '" data-current="' . esc_attr($variation_selected_value) . '"><option value="">' . __('No default', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '&hellip;</option>';
                // Get terms for attribute taxonomy or value if its a custom attribute
                if ($attribute['is_taxonomy']) {
                    $post_terms = wp_get_post_terms($post->ID, $attribute['name']);
                    foreach ($post_terms as $term) {
                        echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>';
                    }
                } else {
                    $options = wc_get_text_attributes($attribute['value']);
                    foreach ($options as $option) {
                        echo '<option ' . selected($variation_selected_value, $option, false) . ' value="' . esc_attr($option) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
                    }
                }
                echo '</select>';
            }
            ?>
					</div>
					<div class="clear"></div>
				</div>

				<div class="toolbar toolbar-top">
					<select id="field_to_edit" class="variation_actions">
						<option value="add_variation"><?php 
            _e('Add variation', 'woocommerce');
            ?>
</option>
						<option value="link_all_variations"><?php 
            _e('Create variations from all attributes', 'woocommerce');
            ?>
</option>
						<option value="delete_all"><?php 
            _e('Delete all variations', 'woocommerce');
            ?>
</option>
						<optgroup label="<?php 
            esc_attr_e('Status', 'woocommerce');
            ?>
">
							<option value="toggle_enabled"><?php 
            _e('Toggle &quot;Enabled&quot;', 'woocommerce');
            ?>
</option>
							<option value="toggle_downloadable"><?php 
            _e('Toggle &quot;Downloadable&quot;', 'woocommerce');
            ?>
</option>
							<option value="toggle_virtual"><?php 
            _e('Toggle &quot;Virtual&quot;', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Pricing', 'woocommerce');
            ?>
">
							<option value="variable_regular_price"><?php 
            _e('Set regular prices', 'woocommerce');
            ?>
</option>
							<option value="variable_regular_price_increase"><?php 
            _e('Increase regular prices (fixed amount or percentage)', 'woocommerce');
            ?>
</option>
							<option value="variable_regular_price_decrease"><?php 
            _e('Decrease regular prices (fixed amount or percentage)', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_price"><?php 
            _e('Set sale prices', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_price_increase"><?php 
            _e('Increase sale prices (fixed amount or percentage)', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_price_decrease"><?php 
            _e('Decrease sale prices (fixed amount or percentage)', 'woocommerce');
            ?>
</option>
							<option value="variable_sale_schedule"><?php 
            _e('Set scheduled sale dates', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Inventory', 'woocommerce');
            ?>
">
							<option value="toggle_manage_stock"><?php 
            _e('Toggle &quot;Manage stock&quot;', 'woocommerce');
            ?>
</option>
							<option value="variable_stock"><?php 
            _e('Stock', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Shipping', 'woocommerce');
            ?>
">
							<option value="variable_length"><?php 
            _e('Length', 'woocommerce');
            ?>
</option>
							<option value="variable_width"><?php 
            _e('Width', 'woocommerce');
            ?>
</option>
							<option value="variable_height"><?php 
            _e('Height', 'woocommerce');
            ?>
</option>
							<option value="variable_weight"><?php 
            _e('Weight', 'woocommerce');
            ?>
</option>
						</optgroup>
						<optgroup label="<?php 
            esc_attr_e('Downloadable products', 'woocommerce');
            ?>
">
							<option value="variable_download_limit"><?php 
            _e('Download limit', 'woocommerce');
            ?>
</option>
							<option value="variable_download_expiry"><?php 
            _e('Download expiry', 'woocommerce');
            ?>
</option>
						</optgroup>
						<?php 
            do_action('woocommerce_variable_product_bulk_edit_actions');
            ?>
					</select>
					<a class="button bulk_edit do_variation_action"><?php 
            _e('Go', 'woocommerce');
            ?>
</a>

					<div class="variations-pagenav">
						<span class="displaying-num"><?php 
            printf(_n('%s item', '%s items', $variations_count, 'woocommerce'), $variations_count);
            ?>
</span>
						<span class="expand-close">
							(<a href="#" class="expand_all"><?php 
            _e('Expand', 'woocommerce');
            ?>
</a> / <a href="#" class="close_all"><?php 
            _e('Close', 'woocommerce');
            ?>
</a>)
						</span>
						<span class="pagination-links">
							<a class="first-page disabled" title="<?php 
            _e('Go to the first page', 'woocommerce');
            ?>
" href="#">&laquo;</a>
							<a class="prev-page disabled" title="<?php 
            _e('Go to the previous page', 'woocommerce');
            ?>
" href="#">&lsaquo;</a>
							<span class="paging-select">
								<label for="current-page-selector-1" class="screen-reader-text"><?php 
            _e('Select Page', 'woocommerce');
            ?>
</label>
								<select class="page-selector" id="current-page-selector-1" title="<?php 
            _e('Current page', 'woocommerce');
            ?>
">
									<?php 
            for ($i = 1; $i <= $variations_total_pages; $i++) {
                ?>
										<option value="<?php 
                echo $i;
                ?>
"><?php 
                echo $i;
                ?>
</option>
									<?php 
            }
            ?>
								</select>
								 <?php 
            _ex('of', 'number of pages', 'woocommerce');
            ?>
 <span class="total-pages"><?php 
            echo $variations_total_pages;
            ?>
</span>
							</span>
							<a class="next-page" title="<?php 
            _e('Go to the next page', 'woocommerce');
            ?>
" href="#">&rsaquo;</a>
							<a class="last-page" title="<?php 
            _e('Go to the last page', 'woocommerce');
            ?>
" href="#">&raquo;</a>
						</span>
					</div>
					<div class="clear"></div>
				</div>

				<div class="woocommerce_variations wc-metaboxes" data-attributes="<?php 
            echo esc_attr(json_encode($attributes));
            ?>
" data-total="<?php 
            echo $variations_count;
            ?>
" data-total_pages="<?php 
            echo $variations_total_pages;
            ?>
" data-page="1" data-edited="false">
				</div>

				<div class="toolbar">
					<button type="button" class="button-primary save-variation-changes" disabled="disabled"><?php 
            _e('Save Changes', 'woocommerce');
            ?>
</button>
					<button type="button" class="button cancel-variation-changes" disabled="disabled"><?php 
            _e('Cancel', 'woocommerce');
            ?>
</button>

					<div class="variations-pagenav">
						<span class="displaying-num"><?php 
            printf(_n('%s item', '%s items', $variations_count, 'woocommerce'), $variations_count);
            ?>
</span>
						<span class="expand-close">
							(<a href="#" class="expand_all"><?php 
            _e('Expand', 'woocommerce');
            ?>
</a> / <a href="#" class="close_all"><?php 
            _e('Close', 'woocommerce');
            ?>
</a>)
						</span>
						<span class="pagination-links">
							<a class="first-page disabled" title="<?php 
            _e('Go to the first page', 'woocommerce');
            ?>
" href="#">&laquo;</a>
							<a class="prev-page disabled" title="<?php 
            _e('Go to the previous page', 'woocommerce');
            ?>
" href="#">&lsaquo;</a>
							<span class="paging-select">
								<label for="current-page-selector-1" class="screen-reader-text"><?php 
            _e('Select Page', 'woocommerce');
            ?>
</label>
								<select class="page-selector" id="current-page-selector-1" title="<?php 
            _e('Current page', 'woocommerce');
            ?>
">
									<?php 
            for ($i = 1; $i <= $variations_total_pages; $i++) {
                ?>
										<option value="<?php 
                echo $i;
                ?>
"><?php 
                echo $i;
                ?>
</option>
									<?php 
            }
            ?>
								</select>
								 <?php 
            _ex('of', 'number of pages', 'woocommerce');
            ?>
 <span class="total-pages"><?php 
            echo $variations_total_pages;
            ?>
</span>
							</span>
							<a class="next-page" title="<?php 
            _e('Go to the next page', 'woocommerce');
            ?>
" href="#">&rsaquo;</a>
							<a class="last-page" title="<?php 
            _e('Go to the last page', 'woocommerce');
            ?>
" href="#">&raquo;</a>
						</span>
					</div>

					<div class="clear"></div>
				</div>

			<?php 
        }
        ?>
		</div></div>
		<?php 
    }
    ?>

	<?php 
}
?>

	<?php 
foreach ($attributes as $attribute) {
    if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
        continue;
    } else {
        $has_row = true;
    }
    ?>
        <?php 
    $name = wc_attribute_label($attribute['name']);
    if (strtolower($name) != 'color') {
        ?>
		<div class="row-fluid">
            <?php 
        $attribute_row = $name;
        if ($attribute['is_taxonomy']) {
            $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
            $attribute_row .= apply_filters('woocommerce_attribute', wptexturize(implode(', ', $values)), $attribute, $values);
        } else {
            // Convert pipes to commas and display values
            $values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
            $attribute_row .= apply_filters('woocommerce_attribute', wptexturize(implode(', ', $values)), $attribute, $values);
        }
        echo $attribute_row;
        ?>
 static function getAttributeLabel($name)
 {
     // use get_product() on WC 2.1+
     if (function_exists('wc_attribute_label')) {
         return wc_attribute_label($name);
     } else {
         // use WC 2.0 method
         global $woocommerce;
         return $woocommerce->attribute_label($name);
     }
 }
Пример #26
0
    /**
     * AJAX Range Taxonomies
     */
    public static function prdctfltr_r_fields()
    {
        $pf_id = isset($_POST['pf_id']) ? $_POST['pf_id'] : 0;
        ob_start();
        ?>

			<h3><?php 
        _e('Range Fitler', 'prdctfltr');
        ?>
</h3>
			<p><?php 
        _e('Setup range filter.', 'prdctfltr');
        ?>
</p>
			<table cass="form-table">
				<tbody>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        printf('<label for="pfr_title_%1$s">%2$s</label>', $pf_id, __('Override Title', 'prdctfltr'));
        ?>
							
						</th>
						<td class="forminp forminp-text">
							<?php 
        printf('<input name="pfr_title[%1$s]" id="pfr_title_%1$s" type="text" value="%2$s" style="width:300px;margin-right:12px;" /></label>', $pf_id, isset($_POST['pfr_title']) ? $_POST['pfr_title'] : '');
        ?>
							<span class="description"><?php 
        _e('Enter title for the current advanced filter. If you leave this field blank default will be used.', 'prdctfltr');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        printf('<label for="pfr_taxonomy_%1$s">%2$s</label>', $pf_id, __('Select Range', 'prdctfltr'));
        ?>
							
						</th>
						<td class="forminp forminp-select">
							<?php 
        $taxonomies = wc_get_attribute_taxonomies();
        printf('<select name="pfr_taxonomy[%1$s]" id="pfr_taxonomy_%1$s" class="prdctfltr_rng_select"  style="width:300px;margin-right:12px;">', $pf_id);
        echo '<option value="price"' . (!isset($_POST['pfr_taxonomy']) || $_POST['pfr_taxonomy'] == 'price' ? ' selected="selected"' : '') . '>' . __('Price range', 'prdctfltr') . '</option>';
        foreach ($taxonomies as $k => $v) {
            $curr_label = wc_attribute_label($v->attribute_name);
            echo '<option value="pa_' . $v->attribute_name . '"' . (isset($_POST['pfr_taxonomy']) && $_POST['pfr_taxonomy'] == 'pa_' . $v->attribute_name ? ' selected="selected"' : '') . '>' . $curr_label . '</option>';
        }
        echo '</select>';
        ?>
							<span class="description"><?php 
        _e('Enter title for the current range filter. If you leave this field blank default will be used.', 'prdctfltr');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        printf('<label for="pfr_include_%1$s">%2$s</label>', $pf_id, __('Include Terms', 'prdctfltr'));
        ?>
							
						</th>
						<td class="forminp forminp-multiselect">
							<?php 
        if (isset($_POST['pfr_taxonomy']) && $_POST['pfr_taxonomy'] !== 'price') {
            $catalog_attrs = get_terms($_POST['pfr_taxonomy']);
            $curr_options = '';
            if (!empty($catalog_attrs) && !is_wp_error($catalog_attrs)) {
                foreach ($catalog_attrs as $term) {
                    $decode_slug = WC_Prdctfltr::prdctfltr_utf8_decode($term->slug);
                    $curr_options .= sprintf('<option value="%1$s"%3$s>%2$s</option>', $decode_slug, $term->name, is_array($_POST['pfr_include']) && in_array($decode_slug, $_POST['pfr_include']) ? ' selected="selected"' : '');
                }
            }
            printf('<select name="pfr_include[%2$s][]" id="pfr_include_%2$s" multiple="multiple" style="width:300px;margin-right:12px;">%1$s</select>', $curr_options, $pf_id);
            $add_disabled = '';
        } else {
            printf('<select name="pfr_include[%1$s][]" id="pfr_include_%1$s" multiple="multiple" disabled style="width:300px;margin-right:12px;"></select></label>', $pf_id);
            $add_disabled = ' disabled';
        }
        ?>
							<span class="description"><?php 
        _e('Select terms to include. Use CTRL+Click to select terms or deselect all.', 'prdctfltr');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        printf('<label for="pfr_orderby_%1$s">%2$s</label>', $pf_id, __('Term Order By', 'prdctfltr'));
        ?>
							
						</th>
						<td class="forminp forminp-select">
						<?php 
        $curr_options = '';
        $orderby_params = array('' => __('None', 'prdctfltr'), 'id' => __('ID', 'prdctfltr'), 'name' => __('Name', 'prdctfltr'), 'number' => __('Number', 'prdctfltr'), 'slug' => __('Slug', 'prdctfltr'), 'count' => __('Count', 'prdctfltr'));
        foreach ($orderby_params as $k => $v) {
            $selected = isset($_POST['pfr_orderby']) && $_POST['pfr_orderby'] == $k ? ' selected="selected"' : '';
            $curr_options .= sprintf('<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected);
        }
        printf('<select name="pfr_orderby[%2$s]" id="pfr_orderby_%2$s"%3$s style="width:300px;margin-right:12px;">%1$s</select></label>', $curr_options, $pf_id, $add_disabled);
        ?>
							<span class="description"><?php 
        _e('Select current range terms order by.', 'prdctfltr');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        printf('<label for="pfr_order_%1$s">%2$s</label>', $pf_id, __('Term Order', 'prdctfltr'));
        ?>
							
						</th>
						<td class="forminp forminp-select">
						<?php 
        $curr_options = '';
        $order_params = array('ASC' => __('ASC', 'prdctfltr'), 'DESC' => __('DESC', 'prdctfltr'));
        foreach ($order_params as $k => $v) {
            $selected = isset($pf_filters_advanced['pfr_order']) && $pf_filters_advanced['pfr_order'] == $k ? ' selected="selected"' : '';
            $curr_options .= sprintf('<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected);
        }
        printf('<select name="pfr_order[%2$s]" id="pfr_order_%2$s"%3$s style="width:300px;margin-right:12px;">%1$s</select>', $curr_options, $pf_id, $add_disabled);
        ?>
							<span class="description"><?php 
        _e('Select ascending or descending order.', 'prdctfltr');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        printf('<label for="pfr_style_%1$s">%2$s</label>', $pf_id, __('Select Style', 'prdctfltr'));
        ?>
							
						</th>
						<td class="forminp forminp-select">
						<?php 
        $curr_options = '';
        $catalog_style = array('flat' => __('Flat', 'prdctfltr'), 'modern' => __('Modern', 'prdctfltr'), 'html5' => __('HTML5', 'prdctfltr'), 'white' => __('White', 'prdctfltr'));
        foreach ($catalog_style as $k => $v) {
            $selected = isset($_POST['pfr_style']) && $_POST['pfr_style'] == $k ? ' selected="selected"' : '';
            $curr_options .= sprintf('<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected);
        }
        printf('<select name="pfr_style[%2$s]" id="pfr_style_%2$s" style="width:300px;margin-right:12px;">%1$s</select>', $curr_options, $pf_id);
        ?>
							<span class="description"><?php 
        _e('Select current range style.', 'prdctfltr');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row" class="titledesc">
						<?php 
        _e('Use Grid', 'prdctfltr');
        ?>
						</th>
						<td class="forminp forminp-checkbox">
							<fieldset>
								<legend class="screen-reader-text">
								<?php 
        _e('Use Grid', 'prdctfltr');
        ?>
								</legend>
								<label for="pfr_grid_<?php 
        echo $pf_id;
        ?>
">
								<?php 
        printf('<input name="pfr_grid[%2$s]" id="pfr_grid_%2$s" type="checkbox" value="yes"%1$s />', isset($_POST['pfr_grid']) && $_POST['pfr_grid'] == 'yes' ? ' checked="checked"' : '', $pf_id);
        _e('Check this option to use grid in current range.', 'prdctfltr');
        ?>
								</label>
							</fieldset>
						</td>
						<tr valign="top">
							<th scope="row" class="titledesc">
							<?php 
        printf('<label for="pfr_custom_%1$s">%2$s</label>', $pf_id, __('Custom Settings', 'prdctfltr'));
        ?>
							</th>
							<td class="forminp forminp-textarea">
								<p style="margin-top:0;"><?php 
        _e('Enter custom settings for the range filter. Visit this page for more information ', 'prdctfltr');
        ?>
 <a href="http://ionden.com/a/plugins/ion.rangeSlider/demo.html" target="_blank">http://ionden.com/a/plugins/ion.rangeSlider/demo.html</a></p>
								<?php 
        printf('<textarea name="pfr_custom[%1$s]" id="pfr_custom_%1$s" type="text" style="wmin-width:600px;margin-top:12px;min-height:150px;">%2$s</textarea>', $pf_id, isset($_POST['pfr_custom']) ? $_POST['pfr_custom'] : '');
        ?>
							</td>
						</tr>
					</tr>

				</tbody>
			</table>
		<?php 
        $html = $pf_id . '%SPLIT%' . ob_get_clean();
        die($html);
        exit;
    }
Пример #27
0
/**
 * Variation Formatting.
 *
 * Gets a formatted version of variation data or item meta.
 *
 * @access public
 * @param string $variation
 * @param bool $flat (default: false)
 * @return string
 */
function wc_get_formatted_variation($variation, $flat = false)
{
    $return = '';
    if (is_array($variation)) {
        if (!$flat) {
            $return = '<dl class="variation">';
        }
        $variation_list = array();
        foreach ($variation as $name => $value) {
            if (!$value) {
                continue;
            }
            // If this is a term slug, get the term's nice name
            if (taxonomy_exists(esc_attr(str_replace('attribute_', '', $name)))) {
                $term = get_term_by('slug', $value, esc_attr(str_replace('attribute_', '', $name)));
                if (!is_wp_error($term) && !empty($term->name)) {
                    $value = $term->name;
                }
            } else {
                $value = ucwords(str_replace('-', ' ', $value));
            }
            if ($flat) {
                $variation_list[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': ' . rawurldecode($value);
            } else {
                $variation_list[] = '<dt>' . wc_attribute_label(str_replace('attribute_', '', $name)) . ':</dt><dd>' . rawurldecode($value) . '</dd>';
            }
        }
        if ($flat) {
            $return .= implode(', ', $variation_list);
        } else {
            $return .= implode('', $variation_list);
        }
        if (!$flat) {
            $return .= '</dl>';
        }
    }
    return $return;
}
Пример #28
0
 /**
  * Add an attribute row
  */
 public static function add_attribute()
 {
     ob_start();
     check_ajax_referer('add-attribute', 'security');
     if (!current_user_can('edit_products')) {
         die(-1);
     }
     global $wc_product_attributes;
     $thepostid = 0;
     $taxonomy = sanitize_text_field($_POST['taxonomy']);
     $i = absint($_POST['i']);
     $position = 0;
     $metabox_class = array();
     $attribute = array('name' => $taxonomy, 'value' => '', 'is_visible' => apply_filters('woocommerce_attribute_default_visibility', 1), 'is_variation' => 0, 'is_taxonomy' => $taxonomy ? 1 : 0);
     if ($taxonomy) {
         $attribute_taxonomy = $wc_product_attributes[$taxonomy];
         $metabox_class[] = 'taxonomy';
         $metabox_class[] = $taxonomy;
         $attribute_label = wc_attribute_label($taxonomy);
     } else {
         $attribute_label = '';
     }
     include 'admin/meta-boxes/views/html-product-attribute.php';
     die;
 }
Пример #29
0
function wpp_export($export)
{
    error_reporting(0);
    ob_clean();
    $export = addslashes(substr(strip_tags($_GET['wpp_export']), 0, 5));
    @set_time_limit(864000);
    if (ini_get('max_execution_time') != 864000) {
        @ini_set('max_execution_time', 864000);
    }
    $post_id = url_to_postid($_SERVER['REQUEST_URI']);
    $post = get_post($post_id);
    if ($post->post_status != 'publish') {
        return false;
    }
    if (post_password_required($post->ID)) {
        return false;
    }
    $product = get_product($post->ID);
    $out = '';
    if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
        $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'shop_single');
        $wpp_featured_image = $thumbnail[0] ? $thumbnail[0] : $thumbnail[0];
    } else {
        $wpp_featured_image = '';
    }
    if ($thumbnail[1]) {
        $wpp_featured_image = '<img width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" src="' . $thumbnail[0] . '"/>';
    }
    $wpp_price_html = strip_tags($product->get_price_html());
    $wpp_title = $post->post_title;
    $wpp_sku = $product->get_sku();
    $wpp_permalink = $product->get_permalink();
    $wpp_stock = $product->get_stock_quantity();
    $wpp_rating = strip_tags($product->get_rating_html());
    $wpp_categories = $product->get_categories(', ');
    $wpp_tags = $product->get_tags(', ');
    $wpp_summary = wpp_text_filter($post->post_excerpt);
    $wpp_description = wpp_text_filter($post->post_content);
    $attribute_html = "\r\n<ul>";
    if ($product->enable_dimensions_display()) {
        $attribute_html .= $product->get_dimensions() ? '<li>' . get_option('wpp_ph_dimensions') . ': ' . $product->get_dimensions() . "\r\n</li>" : '';
    }
    $attribute_html .= $product->get_weight() ? '<li>' . get_option('wpp_ph_weight') . ': ' . $product->get_weight() . ' ' . get_option('woocommerce_weight_unit') . "\r\n</li>" : '';
    if ($product->has_attributes()) {
        $wpp_attributes = $product->get_attributes();
        if (!empty($wpp_attributes)) {
            foreach ($wpp_attributes as $attribute) {
                if (!$attribute['is_visible']) {
                    continue;
                }
                if ($attribute['is_taxonomy']) {
                    $product_terms = wp_get_post_terms($post->ID, $attribute['name']);
                    $p_terms = array();
                    //$attribute_name = ucwords(str_replace('attribute_','',str_replace('pa_','',$attribute['name'])));
                    $attribute_name = wc_attribute_label($attribute['name']);
                    foreach ($product_terms as $p_term) {
                        $p_terms[] = $p_term->name;
                    }
                    $attribute_html .= '<li>' . $attribute_name . ': ' . implode(', ', $p_terms) . "\r\n</li>";
                } else {
                    $attribute_html .= '<li>' . $attribute['name'] . ': ' . $attribute['value'] . "\r\n</li>";
                }
            }
        }
    }
    $attribute_html .= '</ul>';
    $attribute_html = str_replace(array(' |', '|'), ',', $attribute_html);
    $wpp_has_variants = false;
    $wpp_variants = "\r\n<ul>";
    $args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID);
    $variations = get_posts($args);
    if (!empty($variations)) {
        $wpp_has_variants = true;
        foreach ($variations as $variation) {
            $vars = new WC_Product_Variation($variation->ID);
            $wpp_variants .= '<li>' . str_replace($vars->get_sku(), '', html_entity_decode(strip_tags(wpp_text_filter(str_replace('&ndash;', ' - ', $vars->get_formatted_name()))), ENT_QUOTES, "UTF-8")) . "\r\n</li>";
            unset($vars);
        }
        $wpp_variants .= '</ul>';
        $wpp_variants = str_replace(array('<li>  -  ', ',   -  '), array('<li>', '  -  '), $wpp_variants);
    }
    //Post Specific Custom Tabs
    if ($product_meta = get_post_meta($post->ID)) {
        foreach ($product_meta as $meta_key => $meta_value) {
            if (strpos($meta_key, '_wpt_field_') !== FALSE) {
                $custom_tab_slug = str_replace('_wpt_field_', '', $meta_key);
                $custom_tab = get_posts(array('name' => $custom_tab_slug, 'posts_per_page' => 1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish'));
                if (trim($meta_value[0])) {
                    $custom_tab_title_html[] = $custom_tab[0]->post_title;
                    $custom_tab_content_html[] = wpp_text_filter($meta_value[0]);
                }
            }
            continue;
        }
    }
    //General Custom Tabs
    $general_custom_tab = get_posts(array('posts_per_page' => -1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish'));
    foreach ($general_custom_tab as $tab) {
        if (trim($tab->post_content)) {
            $cfkey = '_wpt_field_' . $tab->post_name;
            if (get_post_meta($post->ID, $cfkey, true)) {
                //it's already taken
            } else {
                $custom_tab_title_html[] = $tab->post_title;
                $custom_tab_content_html[] = wpp_text_filter($tab->post_content);
            }
        }
    }
    $wpp_gallery = $product->get_gallery_attachment_ids();
    foreach ($wpp_gallery as $wpp_img) {
        $wpp_gallery_images .= '&nbsp;' . wp_get_attachment_image($wpp_img, 'shop_single') . '&nbsp;';
    }
    if ($export == 'doc') {
        $doc_title = stripslashes($post->post_title);
        $wpp_description = stripslashes($wpp_description);
        $wpp_price = get_option('wpp_ph_price') . ': ' . html_entity_decode(str_replace('&ndash;', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8");
        if (get_option('wpp_save_doc_img_max_width')) {
            $wpp_max_image_width = get_option('wpp_save_doc_img_max_width');
        } else {
            $wpp_max_image_width = 500;
        }
        if (preg_match_all('|width=[\'\\"]*(\\d+)[\'\\"]*[^\\>\\<]+height=[\'\\"]*(\\d+)[\'\\"]*|i', $wpp_description, $doc_img_sizes, PREG_SET_ORDER)) {
            foreach ($doc_img_sizes as $doc_img) {
                $doc_img_w = $doc_img[1];
                $doc_img_h = $doc_img[2];
                if ((int) $wpp_max_image_width < (int) $doc_img_w) {
                    $doc_img_h = $doc_img_h * ($wpp_max_image_width / $doc_img_w);
                    $doc_img_w = $wpp_max_image_width;
                }
                $wpp_description = preg_replace('|width=[\'\\"]*' . $doc_img[1] . '[\'\\"]*[^\\>\\<]+height=[\'\\"]*' . $doc_img[2] . '[\'\\"]*|i', 'width="' . $doc_img_w . '" height="' . $doc_img_h . '"', $wpp_description);
            }
        }
        $wpp_description = preg_replace('|\\[caption[^\\]]+\\]([^\\]]*)\\[\\/caption\\]|is', '$1', $wpp_description);
        $wpp_description = preg_replace(array('|<embed[^>]+>[^>]*<\\/embed>|i', '|<object[^>]+>|i', '|<\\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\\/script>|i'), '', $wpp_description);
        preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER);
        if (!empty($body_array)) {
            for ($i = 0; $i < count($body_array); $i++) {
                $replace = preg_replace('|(.+)class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+align([^\\s\\t\\r\\n\'\\">]+)[^\'\\">]*[\'\\"]+(.+)|i', '</span><![if !vml]> $1 align = \'$2\' $3 <![endif]><span style=\'font-size:10.5pt;color:#666666;\'>', $body_array[$i][0]);
                $wpp_description = str_replace($body_array[$i][0], $replace, $wpp_description);
            }
        }
        $wpp_doc_urls = wpp_img_url($wpp_description);
        if (!empty($wpp_doc_urls)) {
            foreach ($wpp_doc_urls as $k => $v) {
                $wpp_description = str_replace($k, $v, $wpp_description);
            }
        }
        $doc_post_date = $post->post_date;
        $doc_post_date_gmt = $post->post_date_gmt;
        $doc_modified_date = $post->post_modified;
        $doc_modified_date_gmt = $post->post_modified_gmt;
        if (!get_option('wpp_doc_t_image')) {
            $wpp_description = preg_replace('|<img[^><]+>|i', '', $wpp_description);
        }
        $doc_t_title = $doc_title && get_option('wpp_doc_t_title') ? '<h2 style="color:#000000;text-align:' . get_option('wpp_save_text_align') . '">' . $doc_title . '</h2><br>' : '';
        $doc_t_date = get_option('wpp_doc_t_date') ? get_option('wpp_ph_prod_date') . ': ' . $doc_post_date . '<br>' : '';
        $doc_t_md_date = get_option('wpp_doc_t_md') ? get_option('wpp_ph_prod_mod_date') . ': ' . $doc_modified_date : '';
        require WPP_FOLDER . 'template/header/doc_head.php';
        if (get_option('wpp_save_doc_template')) {
            require WPP_FOLDER . 'template/save_as_word_document.php';
        } else {
            require WPP_FOLDER . 'template/save_as_word_document_oo.php';
        }
        $doc = trim($doc);
        $length = strlen($doc);
        $file = trim(str_replace(' ', '-', trim($doc_title)), '-');
        $file = $file . '.doc';
        header('Content-Type: application/msword; charset=utf-8');
        if (headers_sent()) {
            echo 'Some data has already been output, can\'t send MS Doc file';
        }
        header('Content-Length: ' . $length);
        header('Content-Disposition: attachment; filename=' . $file);
        header('Cache-Control: private, max-age=0, must-revalidate');
        header('Pragma: public');
        ini_set('zlib.output_compression', '0');
        echo $doc;
    } elseif ($export == 'pdf') {
        global $wpp_html_link;
        $html_title = stripslashes($post->post_title);
        $wpp_html_link = stripslashes($post->guid);
        //Price Style
        $wpp_price = $product->get_price_html();
        $wpp_price = strpos($wpp_price, '&#x4') === FALSE ? $wpp_price : str_replace('&#x440;&#x443;&#x431;', 'руб', strip_tags($wpp_price));
        if ($product->is_on_sale()) {
            $wpp_price = str_replace(array('<del>', '</del>'), array('^[font][' . get_option('wpp_ph_real_price') . ': ', '][200,200,200][14]^<br>
 ^[font][' . get_option('wpp_ph_curr_sale_price') . ':'), str_replace('&ndash;', ' - ', $wpp_price)) . '][15, 117, 84][14]^';
        } else {
            $wpp_price = '^[font][' . get_option('wpp_ph_price') . ': ' . strip_tags($wpp_price) . '][15, 117, 84][14]^';
        }
        //Limiting image sizes
        preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $html_body, $body_array, PREG_SET_ORDER);
        if (!empty($body_array)) {
            for ($i = 0; $i < count($body_array); $i++) {
                $replace = preg_replace('|(.+)class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+align([^\\s\\t\\r\\n\'\\">]+)[^\'\\">]*[\'\\"]+(.+)|i', '$1 align = "$2" style="padding:5px" $3', $body_array[$i][0]);
                $html_body = str_replace($body_array[$i][0], $replace, $html_body);
            }
        }
        $html_body = preg_replace('|<noscript>.+?</noscript>|is', '', $html_body);
        $html_body = preg_replace("|\r|", "<br>", $html_body);
        $wpp_pdf_urls = wpp_img_url($html_body);
        if (!empty($wpp_pdf_urls)) {
            foreach ($wpp_pdf_urls as $k => $v) {
                if (strpos($k, '../') === FALSE) {
                    $html_body = str_replace($k, $v, $html_body);
                } else {
                    continue;
                }
            }
        }
        require WPP_FOLDER . 'template/header/pdf_head.php';
        require WPP_FOLDER . 'template/save_as_pdf.php';
        require WPP_FOLDER . 'pdf.php';
    } elseif ($export == 'print') {
        $print_title = stripslashes($post->post_title);
        $wpp_description = stripslashes($wpp_description);
        $wpp_price = get_option('wpp_ph_price') . ': ' . html_entity_decode(str_replace('&ndash;', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8");
        if (get_option('wpp_save_print_img_max_width')) {
            $wpp_max_image_width = get_option('wpp_save_print_img_max_width');
        } else {
            $wpp_max_image_width = 500;
        }
        if (preg_match_all('|width=[\'\\"]*(\\d+)[\'\\"]*[^\\>\\<]+height=[\'\\"]*(\\d+)[\'\\"]*|i', $wpp_description, $print_img_sizes, PREG_SET_ORDER)) {
            foreach ($print_img_sizes as $print_img) {
                $print_img_w = $print_img[1];
                $print_img_h = $print_img[2];
                if ((int) $wpp_max_image_width < (int) $print_img_w) {
                    $print_img_h = $print_img_h * ($wpp_max_image_width / $print_img_w);
                    $print_img_w = $wpp_max_image_width;
                }
                $wpp_description = preg_replace('|width=[\'\\"]*' . $print_img[1] . '[\'\\"]*[^\\>\\<]+height=[\'\\"]*' . $print_img[2] . '[\'\\"]*|i', 'width="' . $print_img_w . '" height="' . $print_img_h . '"', $wpp_description);
            }
        }
        $wpp_description = preg_replace('|\\[caption[^\\]]+\\]([^\\]]*)\\[\\/caption\\]|is', '$1', $wpp_description);
        $wpp_description = preg_replace(array('|<embed[^>]+>[^>]*<\\/embed>|i', '|<object[^>]+>|i', '|<\\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\\/script>|i'), '', $wpp_description);
        if (get_option('wpp_pt_links')) {
            preg_match_all("|<a href[\\s\n\t\r]*=[\\s\n\t\r]*[\\'\"]+([^>\\'\"]+)[\\'\"]+[^><]*>([^><]+)</a>|i", $wpp_description, $links_array, PREG_SET_ORDER);
            if (!empty($links_array)) {
                for ($i = 0; $i < count($links_array); $i++) {
                    $print_links .= '<li>' . wpp_phrase_spliter($links_array[$i][1], 50, ' ', false) . '</li>';
                    $wpp_description = str_replace($links_array[$i][0], '<u>' . $links_array[$i][0] . '</u> <sup>' . ($i + 1) . '</sup>', $wpp_description);
                }
            }
        }
        preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER);
        if (!empty($body_array)) {
            for ($i = 0; $i < count($body_array); $i++) {
                $replace = preg_replace('|(.+)class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+align([^\\s\\t\\r\\n\'\\">]+)[^\'\\">]*[\'\\"]+(.+)|i', '$1 align = "$2" style="padding:5px" $3', $body_array[$i][0]);
                $wpp_description = str_replace($body_array[$i][0], $replace, $wpp_description);
            }
        }
        $print_excerpt = stripslashes($post->post_excerpt);
        $print_post_date = $post->post_date;
        $print_post_date_gmt = $post->post_date_gmt;
        $print_modified_date = $post->post_modified;
        $print_modified_date_gmt = $post->post_modified_gmt;
        if (!get_option('wpp_pt_image')) {
            $wpp_description = preg_replace('|<img[^><]+>|i', '', $wpp_description);
        }
        $pt_header = get_option('wpp_pt_head_site') ? '<a href="' . get_option('siteurl') . '" target="_blank" class="wpp_header_2">' . get_option('blogname') . '</a> <br/>' : '';
        $pt_header .= get_option('wpp_pt_head_url') ? '<a href="' . get_permalink($post->ID) . '" target="_blank" class="wpp_header_3">' . get_permalink($post->ID) . '</a> <br />' : '';
        $pt_header .= get_option('wpp_pt_head_date') ? get_option('wpp_ph_exp_date') . ': ' . date("D M j G:i:s Y / O ") . ' GMT<br />' : '';
        $pt_header .= '<hr style="border:none; border-top: #DDDDDD dotted 1px;" />';
        $pt_title = $print_title && get_option('wpp_pt_title') ? '<h2 style="text-align:' . get_option('wpp_save_text_align') . '">' . $print_title . '</h2><br>' : '';
        $pt_links = $print_links && get_option('wpp_pt_links') ? '<strong>' . get_option('wpp_ph_links') . ':</strong> <ol type="1">' . $print_links . '</ol>' : '';
        $pt_date = get_option('wpp_pt_date') ? get_option('wpp_ph_prod_date') . ': ' . $print_post_date . '<br>' : '';
        $pt_md_date = get_option('wpp_pt_md') ? get_option('wpp_ph_prod_mod_date') . ': ' . $print_modified_date . '<br>' : '';
        $pt_footer = get_option('wpp_pt_header') ? '<br>' . get_option('wpp_ph_exp_date') . ': ' . date("D M j G:i:s Y / O ") . ' GMT
		<br> ' . get_option('wpp_ph_page_exported_from') . ' ' . get_option('blogname') . ' 
		[ <a href="' . str_replace(array('&wpp_export=print', '?wpp_export=print'), '', $_SERVER['REQUEST_URI']) . '" target="_blank">' . get_option('siteurl') . '</a> ]<hr/>
		Product Print by <a href="http://www.gvectors.com/?wpp" target="_blank">WooCommerce PDF & Print</a> plugin.' : '';
        require WPP_FOLDER . 'template/header/print_head.php';
        require WPP_FOLDER . 'template/print.php';
        echo $print;
    }
    exit;
}
/**
 * Output a list of variation attributes for use in the cart forms. 
 * used in the plugins template instead of wc_dropdown_variation_attribute_options
 *
 * @param array $args
 * @since 0.0.1
 */
function wc_radio_variation_attribute_options($args = array())
{
    $args = wp_parse_args($args, array('options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => '', 'show_option_none' => __('Choose an option', 'woocommerce')));
    $options = $args['options'];
    $product = $args['product'];
    $attribute = $args['attribute'];
    $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
    $id = $args['id'] ? $args['id'] : sanitize_title($attribute);
    $class = $args['class'];
    $selectedValue = $args['selected'];
    $first = true;
    if (empty($options) && !empty($product) && !empty($attribute)) {
        $attributes = $product->get_variation_attributes();
        $options = $attributes[$attribute];
    }
    echo '<fieldset id=\'' . esc_attr($id) . '\' class=\'' . esc_attr($class) . '\' name=\'' . esc_attr($name) . '\' data-attribute_name=\'' . esc_attr($name) . '\'>';
    echo '<legend>' . wc_attribute_label($attribute) . '</legend>';
    do_action("before_variations_with_radio_buttons_list", $args);
    echo '<div class=\'product_variable_list\'>';
    if (!empty($options)) {
        if ($product && taxonomy_exists($attribute)) {
            // Get terms if this is a taxonomy - ordered. We need the names too.
            $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
            foreach ($terms as $term) {
                if (in_array($term->slug, $options)) {
                    $checkedString = $selectedValue ? checked(sanitize_title($selectedValue), $term->slug, false) : checked($first, true, false);
                    wc_radio_select_button_for_add_to_cart(array("value" => esc_attr($term->slug), "checked" => $checkedString, "content" => $term->name, "name" => sanitize_title($attribute), "description" => $term->description));
                    $first = false;
                }
            }
        } else {
            foreach ($options as $option) {
                // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                $checkedString = $selectedValue ? sanitize_title($selectedValue) === $selectedValue ? checked($selectedValue, sanitize_title($option), false) : checked($selectedValue, $option, false) : checked($first, true, false);
                wc_radio_select_button_for_add_to_cart(array("value" => esc_attr($option), "checked" => $checkedString, "content" => esc_html($option), "name" => sanitize_title($attribute)));
                $first = true;
            }
        }
    }
    echo '</div>';
    do_action("after_variations_with_radio_buttons_list", $args);
    echo '</fieldset>';
}