public function create_vars() { global $product; if (!is_product() || !$product->is_type('variable')) { return; } $att_data_hook = get_option('mp_wc_vdopp_data_hook'); // Hook data $att_dom_sel = get_option('mp_wc_vdopp_dom_selector'); // DOM Selector $att_data_sel = get_option('mp_wc_vdopp_data_selector'); // Data Selector $att_before_size = apply_filters('mp_wc_vdopp_before_size', rtrim(get_option('mp_wc_vdopp_before_size'))) . ' '; $att_before_weight = apply_filters('mp_wc_vdopp_before_weight', rtrim(get_option('mp_wc_vdopp_before_weight'))) . ' '; $att_after_size = apply_filters('mp_wc_vdopp_after_size', ' ' . ltrim(get_option('mp_wc_vdopp_after_size'))); $att_after_weight = apply_filters('mp_wc_vdopp_after_weight', ' ' . ltrim(get_option('mp_wc_vdopp_after_weight'))); $children = $product->get_children($args = '', $output = OBJECT); $i = 0; foreach ($children as $value) { $product_variatons = new WC_Product_Variation($value); if ($product_variatons->exists() && $product_variatons->variation_is_visible()) { $variations = $product_variatons->get_variation_attributes(); foreach ($variations as $key => $variation) { $this->variations[$i][$key] = $variation; } $weight = $product_variatons->get_weight(); if ($weight) { $weight .= get_option('woocommerce_weight_unit'); } $this->variations[$i]['weight'] = $weight; $this->variations[$i]['dimensions'] = str_replace(' ', '', $product_variatons->get_dimensions()); $i++; } } $this->variations = wp_json_encode($this->variations); $params = array('variations' => $this->variations, 'att_data_hook' => $att_data_hook, 'att_dom_sel' => $att_dom_sel, 'att_data_sel' => $att_data_sel, 'att_before_size' => $att_before_size, 'att_before_weight' => $att_before_weight, 'att_after_size' => $att_after_size, 'att_after_weight' => $att_after_weight, 'num_variations' => count($variations)); // enqueue the script wp_enqueue_script('mp_wc_variation_details'); wp_localize_script('mp_wc_variation_details', 'mp_wc_variations', $params); }