public static function attribute_taxonomies() { global $woocommerce; if (!isset($woocommerce)) { return array(); } $attributes = array(); if (function_exists('wc_get_attribute_taxonomies')) { $attribute_taxonomies = wc_get_attribute_taxonomies(); } else { $attribute_taxonomies = $woocommerce->get_attribute_taxonomies(); } if (empty($attribute_taxonomies)) { return array(); } foreach ($attribute_taxonomies as $attribute) { /* FIX TO WOOCOMMERCE 2.1 */ if (function_exists('wc_attribute_taxonomy_name')) { $taxonomy = wc_attribute_taxonomy_name($attribute->attribute_name); } else { $taxonomy = $woocommerce->attribute_taxonomy_name($attribute->attribute_name); } if (taxonomy_exists($taxonomy)) { $attributes[] = $attribute->attribute_name; } } return $attributes; }
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; }
public static function attribute_taxonomies() { global $woocommerce; if (!isset($woocommerce)) { return array(); } $attributes = array(); if (function_exists('wc_get_attribute_taxonomies') && function_exists('wc_attribute_taxonomy_name')) { $attribute_taxonomies = wc_get_attribute_taxonomies(); if (empty($attribute_taxonomies)) { return array(); } foreach ($attribute_taxonomies as $attribute) { $tax = wc_attribute_taxonomy_name($attribute->attribute_name); if (taxonomy_exists($tax)) { $attributes[$tax] = ucfirst($attribute->attribute_name); } } } else { $attribute_taxonomies = $woocommerce->get_attribute_taxonomies(); if (empty($attribute_taxonomies)) { return array(); } foreach ($attribute_taxonomies as $attribute) { $tax = $woocommerce->attribute_taxonomy_name($attribute->attribute_name); if (taxonomy_exists($tax)) { $attributes[$tax] = ucfirst($attribute->attribute_name); } } } return $attributes; }
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; }
/** * Load the restrictions from the database */ private function LoadRestrictions() { if ($this->restrictions_loaded) { return; } // Attribute/Variation Restrictions $attribute_taxonomies = wc_get_attribute_taxonomies(); $taxonomies = array(); foreach ($attribute_taxonomies as $taxonomy) { $taxonomies[] = wc_attribute_taxonomy_name($taxonomy->attribute_name); } $restrictions = get_terms(array('taxonomy' => $taxonomies, 'meta_query' => array(array('key' => 'multiple_of', 'compare' => 'EXISTS')), 'hide_empty' => false)); if (is_array($restrictions)) { foreach ($restrictions as $restriction) { $this->multiple_ofs_attributes[$restriction->term_id] = $this->GetMultipleOfForAttribute($restriction->term_id); if (!$this->multiple_ofs_attributes[$restriction->term_id]) { unset($this->multiple_ofs_attributes[$restriction->term_id]); } } } // Category Restrictions $restrictions = get_terms(array('taxonomy' => 'product_cat', 'meta_query' => array(array('key' => 'cat_multiple_of', 'compare' => 'EXISTS')), 'hide_empty' => false)); if (is_array($restrictions)) { foreach ($restrictions as $restriction) { $this->multiple_ofs_categories[$restriction->term_id] = $this->GetMultipleOfForCategory($restriction->term_id); if (!$this->multiple_ofs_categories[$restriction->term_id]) { unset($this->multiple_ofs_categories[$restriction->term_id]); } } } $this->cart_must_be_multiple_of = intval(get_option('woocommerce_cart_multiple_of', 0)); $this->restrictions_loaded = true; }
/** * Layered Nav Init * * @package WooCommerce/Widgets * @access public * @return void */ public function woocommerce_layered_nav_init() { if (is_active_widget(false, false, 'yith-woo-ajax-navigation', true) && !is_admin()) { global $_chosen_attributes, $woocommerce; $_chosen_attributes = array(); /* FIX TO WOOCOMMERCE 2.1 */ $attibute_taxonomies = function_exists('wc_get_attribute_taxonomies') ? $attribute_taxonomies = wc_get_attribute_taxonomies() : ($attribute_taxonomies = $woocommerce->get_attribute_taxonomies()); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $attribute = wc_sanitize_taxonomy_name($tax->attribute_name); /* FIX TO WOOCOMMERCE 2.1 */ if (function_exists('wc_attribute_taxonomy_name')) { $taxonomy = wc_attribute_taxonomy_name($attribute); } else { $taxonomy = $woocommerce->attribute_taxonomy_name($attribute); } $name = 'filter_' . $attribute; $query_type_name = 'query_type_' . $attribute; if (!empty($_GET[$name]) && taxonomy_exists($taxonomy)) { $_chosen_attributes[$taxonomy]['terms'] = explode(',', $_GET[$name]); if (empty($_GET[$query_type_name]) || !in_array(strtolower($_GET[$query_type_name]), array('and', 'or'))) { $_chosen_attributes[$taxonomy]['query_type'] = apply_filters('woocommerce_layered_nav_default_query_type', 'and'); } else { $_chosen_attributes[$taxonomy]['query_type'] = strtolower($_GET[$query_type_name]); } } } } if (version_compare(preg_replace('/-beta-([0-9]+)/', '', $woocommerce->version), '2.1', '<')) { add_filter('loop_shop_post_in', 'woocommerce_layered_nav_query'); } else { add_filter('loop_shop_post_in', array(WC()->query, 'layered_nav_query')); } } }
/** * Automatic Set all Product Attribute as Compare Features * */ public function automatic_add_features() { $current_db_version = get_option('woocommerce_db_version', null); if (version_compare($current_db_version, '2.1.0', '<') && null !== $current_db_version) { global $woocommerce; $top_variations = $woocommerce->get_attribute_taxonomies(); } else { $top_variations = wc_get_attribute_taxonomies(); } if ($top_variations) { foreach ($top_variations as $top_variation) { $check_existed = WC_Compare_Data::get_count("field_name='" . trim(addslashes($top_variation->attribute_label)) . "'"); if ($check_existed < 1) { $child_variations = get_terms(version_compare($current_db_version, '2.1.0', '<') && null !== $current_db_version ? $woocommerce->attribute_taxonomy_name($top_variation->attribute_name) : wc_attribute_taxonomy_name($top_variation->attribute_name), array('parent' => 0, 'hide_empty' => 0, 'hierarchical' => 0)); $default_value = ''; if (count($child_variations) > 0) { $line = ''; foreach ($child_variations as $child_variation) { $default_value .= $line . addslashes($child_variation->name); $line = ' '; } } if (trim($default_value) != '') { $feature_id = WC_Compare_Data::insert_row(array('field_name' => trim(addslashes($top_variation->attribute_label)), 'field_type' => 'checkbox', 'field_unit' => '', 'default_value' => $default_value)); } else { $feature_id = WC_Compare_Data::insert_row(array('field_name' => trim(addslashes($top_variation->attribute_label)), 'field_type' => 'input-text', 'field_unit' => '', 'default_value' => '')); } } } } }
/** * Register core taxonomies. */ public static function register_taxonomies() { if (taxonomy_exists('product_type')) { return; } do_action('woocommerce_register_taxonomy'); $permalinks = get_option('woocommerce_permalinks'); register_taxonomy('product_type', apply_filters('woocommerce_taxonomy_objects_product_type', array('product')), apply_filters('woocommerce_taxonomy_args_product_type', array('hierarchical' => false, 'show_ui' => false, 'show_in_nav_menus' => false, 'query_var' => is_admin(), 'rewrite' => false, 'public' => false))); register_taxonomy('product_cat', apply_filters('woocommerce_taxonomy_objects_product_cat', array('product')), apply_filters('woocommerce_taxonomy_args_product_cat', array('hierarchical' => true, 'update_count_callback' => '_wc_term_recount', 'label' => __('Product Categories', 'woocommerce'), 'labels' => array('name' => __('Product Categories', 'woocommerce'), 'singular_name' => __('Product Category', 'woocommerce'), 'menu_name' => _x('Categories', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search Product Categories', 'woocommerce'), 'all_items' => __('All Product Categories', 'woocommerce'), 'parent_item' => __('Parent Product Category', 'woocommerce'), 'parent_item_colon' => __('Parent Product Category:', 'woocommerce'), 'edit_item' => __('Edit Product Category', 'woocommerce'), 'update_item' => __('Update Product Category', 'woocommerce'), 'add_new_item' => __('Add New Product Category', 'woocommerce'), 'new_item_name' => __('New Product Category Name', 'woocommerce')), 'show_ui' => true, 'query_var' => true, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => array('slug' => empty($permalinks['category_base']) ? _x('product-category', 'slug', 'woocommerce') : $permalinks['category_base'], 'with_front' => false, 'hierarchical' => true)))); register_taxonomy('product_tag', apply_filters('woocommerce_taxonomy_objects_product_tag', array('product')), apply_filters('woocommerce_taxonomy_args_product_tag', array('hierarchical' => false, 'update_count_callback' => '_wc_term_recount', 'label' => __('Product Tags', 'woocommerce'), 'labels' => array('name' => __('Product Tags', 'woocommerce'), 'singular_name' => __('Product Tag', 'woocommerce'), 'menu_name' => _x('Tags', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search Product Tags', 'woocommerce'), 'all_items' => __('All Product Tags', 'woocommerce'), 'edit_item' => __('Edit Product Tag', 'woocommerce'), 'update_item' => __('Update Product Tag', 'woocommerce'), 'add_new_item' => __('Add New Product Tag', 'woocommerce'), 'new_item_name' => __('New Product Tag Name', 'woocommerce'), 'popular_items' => __('Popular Product Tags', 'woocommerce'), 'separate_items_with_commas' => __('Separate Product Tags with commas', 'woocommerce'), 'add_or_remove_items' => __('Add or remove Product Tags', 'woocommerce'), 'choose_from_most_used' => __('Choose from the most used Product tags', 'woocommerce'), 'not_found' => __('No Product Tags found', 'woocommerce')), 'show_ui' => true, 'query_var' => true, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => array('slug' => empty($permalinks['tag_base']) ? _x('product-tag', 'slug', 'woocommerce') : $permalinks['tag_base'], 'with_front' => false)))); register_taxonomy('product_shipping_class', apply_filters('woocommerce_taxonomy_objects_product_shipping_class', array('product', 'product_variation')), apply_filters('woocommerce_taxonomy_args_product_shipping_class', array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => __('Shipping Classes', 'woocommerce'), 'labels' => array('name' => __('Shipping Classes', 'woocommerce'), 'singular_name' => __('Shipping Class', 'woocommerce'), 'menu_name' => _x('Shipping Classes', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search Shipping Classes', 'woocommerce'), 'all_items' => __('All Shipping Classes', 'woocommerce'), 'parent_item' => __('Parent Shipping Class', 'woocommerce'), 'parent_item_colon' => __('Parent Shipping Class:', 'woocommerce'), 'edit_item' => __('Edit Shipping Class', 'woocommerce'), 'update_item' => __('Update Shipping Class', 'woocommerce'), 'add_new_item' => __('Add New Shipping Class', 'woocommerce'), 'new_item_name' => __('New Shipping Class Name', 'woocommerce')), 'show_ui' => false, 'show_in_nav_menus' => false, 'query_var' => is_admin(), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => false))); global $wc_product_attributes; $wc_product_attributes = array(); if ($attribute_taxonomies = wc_get_attribute_taxonomies()) { foreach ($attribute_taxonomies as $tax) { if ($name = wc_attribute_taxonomy_name($tax->attribute_name)) { $tax->attribute_public = absint(isset($tax->attribute_public) ? $tax->attribute_public : 1); $label = !empty($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name; $wc_product_attributes[$name] = $tax; $taxonomy_data = array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => $label, 'singular_name' => $label, 'search_items' => sprintf(__('Search %s', 'woocommerce'), $label), 'all_items' => sprintf(__('All %s', 'woocommerce'), $label), 'parent_item' => sprintf(__('Parent %s', 'woocommerce'), $label), 'parent_item_colon' => sprintf(__('Parent %s:', 'woocommerce'), $label), 'edit_item' => sprintf(__('Edit %s', 'woocommerce'), $label), 'update_item' => sprintf(__('Update %s', 'woocommerce'), $label), 'add_new_item' => sprintf(__('Add New %s', 'woocommerce'), $label), 'new_item_name' => sprintf(__('New %s', 'woocommerce'), $label)), 'show_ui' => false, 'query_var' => 1 === $tax->attribute_public, 'rewrite' => false, 'sort' => false, 'public' => 1 === $tax->attribute_public, 'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters('woocommerce_attribute_show_in_nav_menus', false, $name), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms')); if (1 === $tax->attribute_public) { $taxonomy_data['rewrite'] = array('slug' => empty($permalinks['attribute_base']) ? '' : trailingslashit($permalinks['attribute_base']) . sanitize_title($tax->attribute_name), 'with_front' => false, 'hierarchical' => true); } register_taxonomy($name, apply_filters("woocommerce_taxonomy_objects_{$name}", array('product')), apply_filters("woocommerce_taxonomy_args_{$name}", $taxonomy_data)); } } do_action('woocommerce_after_register_taxonomy'); } }
/** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) { return; } $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $taxonomy = isset($instance['attribute']) ? wc_attribute_taxonomy_name($instance['attribute']) : $this->settings['attribute']['std']; $query_type = isset($instance['query_type']) ? $instance['query_type'] : $this->settings['query_type']['std']; $display_type = isset($instance['display_type']) ? $instance['display_type'] : $this->settings['display_type']['std']; if (!taxonomy_exists($taxonomy)) { return; } $get_terms_args = array('hide_empty' => '1'); $orderby = wc_attribute_orderby($taxonomy); switch ($orderby) { case 'name': $get_terms_args['orderby'] = 'name'; $get_terms_args['menu_order'] = false; break; case 'id': $get_terms_args['orderby'] = 'id'; $get_terms_args['order'] = 'ASC'; $get_terms_args['menu_order'] = false; break; case 'menu_order': $get_terms_args['menu_order'] = 'ASC'; break; } $terms = get_terms($taxonomy, $get_terms_args); if (0 === sizeof($terms)) { return; } switch ($orderby) { case 'name_num': usort($terms, '_wc_get_product_terms_name_num_usort_callback'); break; case 'parent': usort($terms, '_wc_get_product_terms_parent_usort_callback'); break; } ob_start(); $this->widget_start($args, $instance); if ('dropdown' === $display_type) { $found = $this->layered_nav_dropdown($terms, $taxonomy, $query_type); } else { $found = $this->layered_nav_list($terms, $taxonomy, $query_type); } $this->widget_end($args); // Force found when option is selected - do not force found on taxonomy attributes if (!is_tax() && is_array($_chosen_attributes) && array_key_exists($taxonomy, $_chosen_attributes)) { $found = true; } if (!$found) { ob_end_clean(); } else { echo ob_get_clean(); } }
public static function wc_attribute_taxonomy_name($name) { if (self::is_wc_version_gte_2_1()) { return wc_attribute_taxonomy_name($name); } else { global $woocommerce; return $woocommerce->attribute_taxonomy_name($name); } }
/** * Get an array of product attribute taxonomies. * * @access public * @return array */ function wc_get_attribute_taxonomy_names() { $taxonomy_names = array(); $attribute_taxonomies = wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $taxonomy_names[] = wc_attribute_taxonomy_name($tax->attribute_name); } } return $taxonomy_names; }
/** * Get all possible woocommerce attribute taxonomies * * @return mixed|void */ function br_aapf_get_attributes() { $attribute_taxonomies = wc_get_attribute_taxonomies(); $attributes = array(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $attributes[wc_attribute_taxonomy_name($tax->attribute_name)] = $tax->attribute_label; } } return apply_filters('berocket_aapf_get_attributes', $attributes); }
public function get_list_attribute_slug() { $list = $this->get_list_attributes(); $return = array(); foreach ($list as $item) { $return[$item->attribute_id]['id'] = $item->attribute_id; $return[$item->attribute_id]['tax_slug'] = wc_attribute_taxonomy_name($item->attribute_name); $return[$item->attribute_id]['name'] = $item->attribute_name; $return[$item->attribute_id]['label'] = $item->attribute_label; } return $return; }
protected function get_woo_attribute_taxonomies() { $attribute_array = array(); $attribute_taxonomies = wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { if (taxonomy_exists(wc_attribute_taxonomy_name($tax->attribute_name))) { $attribute_array[$tax->attribute_name] = $tax->attribute_name; } } } return $attribute_array; }
function constant() { $this->attr_slug = ''; $attribute_name = wc_attribute_taxonomy_name($this->term_slug); $attribute_name_array = wc_get_attribute_taxonomy_names(); $taxonomy_exists = in_array($attribute_name, $attribute_name_array); if ($taxonomy_exists) { $this->attr_slug = $attribute_name; add_image_size('ts_prod_color_thumb', 30, 30, true); $this->init_handle(); add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts')); } }
function yith_ywraq_get_product_meta($raq, $echo = true) { /** * Return the product meta in a varion product * * @param array $raq * @param bool $echo * * @return string * @since 1.0.0 */ $item_data = array(); // Variation data if (!empty($raq['variation_id']) && is_array($raq['variations'])) { foreach ($raq['variations'] 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); } else { $custom_att = str_replace('attribute_', '', $name); if ($custom_att != '') { $label = wc_attribute_label($custom_att); } else { $label = $name; } } $item_data[] = array('key' => $label, 'value' => $value); } } $out = ""; // Output flat or in list format if (sizeof($item_data) > 0) { foreach ($item_data as $data) { if ($echo) { echo esc_html($data['key']) . ': ' . wp_kses_post($data['value']) . "\n"; } else { $out .= ' - ' . esc_html($data['key']) . ': ' . wp_kses_post($data['value']) . ' '; } } } return $out; }
function test_translate_attributes_label_in_wp_taxonomies() { global $wp_taxonomies, $sitepress, $WPML_String_Translation; $WPML_String_Translation->init_active_languages(); $label = 'Test attr'; $name = wc_attribute_taxonomy_name($label); $taxonomy_data = array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => $label, 'singular_name' => $label, 'search_items' => sprintf(__('Search %s', 'woocommerce'), $label), 'all_items' => sprintf(__('All %s', 'woocommerce'), $label), 'parent_item' => sprintf(__('Parent %s', 'woocommerce'), $label), 'parent_item_colon' => sprintf(__('Parent %s:', 'woocommerce'), $label), 'edit_item' => sprintf(__('Edit %s', 'woocommerce'), $label), 'update_item' => sprintf(__('Update %s', 'woocommerce'), $label), 'add_new_item' => sprintf(__('Add New %s', 'woocommerce'), $label), 'new_item_name' => sprintf(__('New %s', 'woocommerce'), $label)), 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'meta_box_cb' => false, 'query_var' => 1, 'rewrite' => false, 'sort' => false, 'public' => 1, 'show_in_nav_menus' => 1, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms')); $taxonomy_data['rewrite'] = array('slug' => empty($permalinks['attribute_base']) ? '' : trailingslashit($permalinks['attribute_base']) . sanitize_title($label), 'with_front' => false, 'hierarchical' => true); do_action('wpml_register_single_string', 'WordPress', 'taxonomy singular name: ' . $label, $label); $string_id = icl_get_string_id($label, 'WordPress', 'taxonomy singular name: ' . $label); icl_add_string_translation($string_id, 'es', 'Test attr es', ICL_TM_COMPLETE); $WPML_String_Translation->clear_string_filter('es'); $sitepress->switch_lang('es'); register_taxonomy($name, apply_filters("woocommerce_taxonomy_objects_{$name}", array('product')), apply_filters("woocommerce_taxonomy_args_{$name}", $taxonomy_data)); $this->assertTrue((bool) has_filter('wpml_translate_single_string')); $this->assertEquals('Test attr es', $wp_taxonomies[$name]->labels->name); }
/** * Constructor * * @param WC_Variation_Restrictions $instance */ public function __construct() { add_filter('woocommerce_products_general_settings', array($this, 'Settings')); // Category restriction settings add_action("product_cat_edit_form_fields", array($this, 'EditProductCategory')); add_action("edit_product_cat", array($this, 'SaveProductCategory')); // Product attribute/variation restriction setings $attribute_taxonomies = wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { // For each of WooCommerce's custom product attributes $attribute_name = wc_attribute_taxonomy_name($tax->attribute_name); add_action("{$attribute_name}_edit_form_fields", array($this, 'EditAttributeTerm')); add_action("edit_{$attribute_name}", array($this, 'SaveAttributeTerm'), 10, 2); } } }
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; }
function widget($args, $instance) { extract($args, EXTR_SKIP); global $woocommerce; $_attributes_array = array(); if (version_compare(WOOCOMMERCE_VERSION, "2.0.99") >= 0) { $attribute_taxonomies = wc_get_attribute_taxonomies(); } else { $attribute_taxonomies = $woocommerce->get_attribute_taxonomies(); } if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $attribute = sanitize_title($tax->attribute_name); if (version_compare(WOOCOMMERCE_VERSION, "2.0.99") >= 0) { $taxonomy = wc_attribute_taxonomy_name($attribute); } else { $taxonomy = $woocommerce->attribute_taxonomy_name($attribute); } // create an array of product attribute taxonomies $_attributes_array[] = $taxonomy; } } if (!is_post_type_archive('product') && !is_tax(array_merge($_attributes_array, array('product_cat', 'product_tag')))) { return; } if (is_tax('product_tag')) { return; } echo $before_widget; if (!empty($instance['title'])) { echo $before_title . $instance['title'] . $after_title; } // Tag list $tags = get_terms('product_tag'); $html = '<ul class="woo-ajax-tags taglist">'; foreach ($tags as $tag) { $term_id = (int) $tag->term_id; $tag_link = get_term_link($term_id, 'product_tag'); $html .= "<li><input type=checkbox id='{$tag->slug}' class=tags name=tag value='{$tag->slug}'> <label for='{$tag->slug}'>{$tag->name}</label></li>"; } $html .= '</ul>'; echo $html; echo $after_widget; }
/** * Index Woocommerce taxonomies * * @param array $taxonomies Index taxonomies array. * @param array $post Post properties array. * @since 2.1 * @return array */ function ep_wc_whitelist_taxonomies($taxonomies, $post) { $woo_taxonomies = array(); $product_type = get_taxonomy('product_type'); $woo_taxonomies[] = $product_type; /** * Note product_shipping_class, product_cat, and product_tag are already public. Make * sure to index non-attribute taxonomies. */ if ($attribute_taxonomies = wc_get_attribute_taxonomies()) { foreach ($attribute_taxonomies as $tax) { if ($name = wc_attribute_taxonomy_name($tax->attribute_name)) { if (empty($tax->attribute_)) { $woo_taxonomies[] = get_taxonomy($name); } } } } return array_merge($taxonomies, $woo_taxonomies); }
/** * * @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 ''; }
public function product_option_terms($tax, $i) { global $woocommerce, $thepostid; if (in_array($tax->attribute_type, array('image'))) { $attribute_taxonomy_name = wc_attribute_taxonomy_name($tax->attribute_name); ?> <select multiple="multiple" data-placeholder="<?php _e('Select terms', 'wpb'); ?> " class="multiselect attribute_values wc-enhanced-select" name="attribute_values[<?php echo $i; ?> ][]"> <?php $all_terms = get_terms($attribute_taxonomy_name, 'orderby=name&hide_empty=0'); if ($all_terms) { foreach ($all_terms as $term) { $has_term = has_term((int) $term->term_id, $attribute_taxonomy_name, $thepostid) ? 1 : 0; echo '<option value="' . esc_attr($term->slug) . '" ' . selected($has_term, 1, false) . '>' . $term->name . '</option>'; } } ?> </select> <button class="button plus select_all_attributes"><?php _e('Select all', 'wpb'); ?> </button> <button class="button minus select_no_attributes"><?php _e('Select none', 'wpb'); ?> </button> <button class="button fr plus add_new_attribute" data-attribute="<?php echo $attribute_taxonomy_name; ?> "><?php _e('Add new', 'wpb'); ?> </button> <?php } }
/** * Layered Nav Init * * @global array $_chosen_attributes * * @return false if not layered nav filter */ public function layeredNavInit() { if (!(is_active_widget(false, false, 'woocommerce_layered_nav', true) && !is_admin())) { return false; } global $_chosen_attributes; $attributes = wc_get_attribute_taxonomies(); foreach ($attributes as $tax) { $attribute = wc_sanitize_taxonomy_name($tax->attribute_name); $taxonomy = wc_attribute_taxonomy_name($attribute); $name = 'filter_' . $attribute; if (!(!empty($_GET[$name]) && taxonomy_exists($taxonomy))) { continue; } $terms = explode(',', $_GET[$name]); $termsTranslations = array(); foreach ($terms as $ID) { $translation = pll_get_term($ID); $termsTranslations[] = $translation ? $translation : $ID; } $_GET[$name] = implode(',', $termsTranslations); $_chosen_attributes[$taxonomy]['terms'] = $termsTranslations; } }
/** * Delete a product attribute * * @since 2.4.0 * @param int $id the product attribute ID * @return array */ public function delete_product_attribute($id) { global $wpdb; try { // Check permissions if (!current_user_can('manage_product_terms')) { throw new WC_API_Exception('woocommerce_api_user_cannot_delete_product_attribute', __('You do not have permission to delete product attributes', 'woocommerce'), 401); } $id = absint($id); $attribute_name = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT attribute_name\n\t\t\t\tFROM {$wpdb->prefix}woocommerce_attribute_taxonomies\n\t\t\t\tWHERE attribute_id = %d\n\t\t\t ", $id)); if (is_null($attribute_name)) { throw new WC_API_Exception('woocommerce_api_invalid_product_attribute_id', __('A product attribute with the provided ID could not be found', 'woocommerce'), 404); } $deleted = $wpdb->delete($wpdb->prefix . 'woocommerce_attribute_taxonomies', array('attribute_id' => $id), array('%d')); if (false === $deleted) { throw new WC_API_Exception('woocommerce_api_cannot_delete_product_attribute', __('Could not delete the attribute', 'woocommerce'), 401); } $taxonomy = wc_attribute_taxonomy_name($attribute_name); if (taxonomy_exists($taxonomy)) { $terms = get_terms($taxonomy, 'orderby=name&hide_empty=0'); foreach ($terms as $term) { wp_delete_term($term->term_id, $taxonomy); } } do_action('woocommerce_attribute_deleted', $id, $attribute_name, $taxonomy); do_action('woocommerce_api_delete_product_attribute', $id, $this); // Clear transients delete_transient('wc_attribute_taxonomies'); return array('message' => sprintf(__('Deleted %s', 'woocommerce'), 'product_attribute')); } catch (WC_API_Exception $e) { return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); } }
/** * Layered Nav Init. */ public static function get_layered_nav_chosen_attributes() { if (!is_array(self::$_chosen_attributes)) { self::$_chosen_attributes = array(); if ($attribute_taxonomies = wc_get_attribute_taxonomies()) { foreach ($attribute_taxonomies as $tax) { $attribute = wc_sanitize_taxonomy_name($tax->attribute_name); $taxonomy = wc_attribute_taxonomy_name($attribute); $filter_terms = !empty($_GET['filter_' . $attribute]) ? explode(',', wc_clean($_GET['filter_' . $attribute])) : array(); if (empty($filter_terms) || !taxonomy_exists($taxonomy)) { continue; } $query_type = !empty($_GET['query_type_' . $attribute]) && in_array($_GET['query_type_' . $attribute], array('and', 'or')) ? wc_clean($_GET['query_type_' . $attribute]) : ''; self::$_chosen_attributes[$taxonomy]['terms'] = array_map('sanitize_title', $filter_terms); // Ensures correct encoding self::$_chosen_attributes[$taxonomy]['query_type'] = $query_type ? $query_type : apply_filters('woocommerce_layered_nav_default_query_type', 'and'); } } } return self::$_chosen_attributes; }
/** * Output the metabox */ public static function output($post) { global $post, $thepostid; wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); $thepostid = $post->ID; if ($terms = wp_get_object_terms($post->ID, 'product_type')) { $product_type = sanitize_title(current($terms)->name); } else { $product_type = apply_filters('default_product_type', 'simple'); } $product_type_selector = apply_filters('product_type_selector', array('simple' => __('Simple product', 'woocommerce'), 'grouped' => __('Grouped product', 'woocommerce'), 'external' => __('External/Affiliate product', 'woocommerce'), 'variable' => __('Variable product', 'woocommerce')), $product_type); $type_box = '<label for="product-type"><select id="product-type" name="product-type"><optgroup label="' . __('Product Type', 'woocommerce') . '">'; foreach ($product_type_selector as $value => $label) { $type_box .= '<option value="' . esc_attr($value) . '" ' . selected($product_type, $value, false) . '>' . esc_html($label) . '</option>'; } $type_box .= '</optgroup></select></label>'; $product_type_options = apply_filters('product_type_options', array('virtual' => array('id' => '_virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woocommerce'), 'description' => __('Virtual products are intangible and aren\'t shipped.', 'woocommerce'), 'default' => 'no'), 'downloadable' => array('id' => '_downloadable', 'wrapper_class' => 'show_if_simple', 'label' => __('Downloadable', 'woocommerce'), 'description' => __('Downloadable products give access to a file upon purchase.', 'woocommerce'), 'default' => 'no'))); foreach ($product_type_options as $key => $option) { $selected_value = get_post_meta($post->ID, '_' . $key, true); if ('' == $selected_value && isset($option['default'])) { $selected_value = $option['default']; } $type_box .= '<label for="' . esc_attr($option['id']) . '" class="' . esc_attr($option['wrapper_class']) . ' tips" data-tip="' . esc_attr($option['description']) . '">' . esc_html($option['label']) . ': <input type="checkbox" name="' . esc_attr($option['id']) . '" id="' . esc_attr($option['id']) . '" ' . checked($selected_value, 'yes', false) . ' /></label>'; } ?> <div class="panel-wrap product_data"> <span class="type_box"> — <?php echo $type_box; ?> </span> <ul class="product_data_tabs wc-tabs" style="display:none;"> <?php $product_data_tabs = apply_filters('woocommerce_product_data_tabs', array('general' => array('label' => __('General', 'woocommerce'), 'target' => 'general_product_data', 'class' => array('hide_if_grouped')), 'inventory' => array('label' => __('Inventory', 'woocommerce'), 'target' => 'inventory_product_data', 'class' => array('show_if_simple', 'show_if_variable', 'show_if_grouped')), 'shipping' => array('label' => __('Shipping', 'woocommerce'), 'target' => 'shipping_product_data', 'class' => array('hide_if_virtual', 'hide_if_grouped', 'hide_if_external')), 'linked_product' => array('label' => __('Linked Products', 'woocommerce'), 'target' => 'linked_product_data', 'class' => array()), 'attribute' => array('label' => __('Attributes', 'woocommerce'), 'target' => 'product_attributes', 'class' => array()), 'variations' => array('label' => __('Variations', 'woocommerce'), 'target' => 'variable_product_options', 'class' => array('variations_tab', 'show_if_variable')), 'advanced' => array('label' => __('Advanced', 'woocommerce'), 'target' => 'advanced_product_data', 'class' => array()))); foreach ($product_data_tabs as $key => $tab) { ?> <li class="<?php echo $key; ?> _options <?php echo $key; ?> _tab <?php echo implode(' ', $tab['class']); ?> "> <a href="#<?php echo $tab['target']; ?> "><?php echo esc_html($tab['label']); ?> </a> </li><?php } do_action('woocommerce_product_write_panel_tabs'); ?> </ul> <div id="general_product_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group hide_if_grouped">'; // SKU if (wc_product_sku_enabled()) { woocommerce_wp_text_input(array('id' => '_sku', 'label' => '<abbr title="' . __('Stock Keeping Unit', 'woocommerce') . '">' . __('SKU', 'woocommerce') . '</abbr>', 'desc_tip' => 'true', 'description' => __('SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce'))); } else { echo '<input type="hidden" name="_sku" value="' . esc_attr(get_post_meta($thepostid, '_sku', true)) . '" />'; } do_action('woocommerce_product_options_sku'); echo '</div>'; echo '<div class="options_group show_if_external">'; // External URL woocommerce_wp_text_input(array('id' => '_product_url', 'label' => __('Product URL', 'woocommerce'), 'placeholder' => 'http://', 'description' => __('Enter the external URL to the product.', 'woocommerce'))); // Button text woocommerce_wp_text_input(array('id' => '_button_text', 'label' => __('Button text', 'woocommerce'), 'placeholder' => _x('Buy product', 'placeholder', 'woocommerce'), 'description' => __('This text will be shown on the button linking to the external product.', 'woocommerce'))); echo '</div>'; echo '<div class="options_group pricing show_if_simple show_if_external">'; // Price woocommerce_wp_text_input(array('id' => '_regular_price', 'label' => __('Regular Price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'data_type' => 'price')); // Special Price woocommerce_wp_text_input(array('id' => '_sale_price', 'data_type' => 'price', 'label' => __('Sale Price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'description' => '<a href="#" class="sale_schedule">' . __('Schedule', 'woocommerce') . '</a>')); // Special Price date range $sale_price_dates_from = ($date = get_post_meta($thepostid, '_sale_price_dates_from', true)) ? date_i18n('Y-m-d', $date) : ''; $sale_price_dates_to = ($date = get_post_meta($thepostid, '_sale_price_dates_to', true)) ? date_i18n('Y-m-d', $date) : ''; echo '<p class="form-field sale_price_dates_fields"> <label for="_sale_price_dates_from">' . __('Sale Price Dates', 'woocommerce') . '</label> <input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . esc_attr($sale_price_dates_from) . '" placeholder="' . _x('From…', 'placeholder', 'woocommerce') . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> <input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . esc_attr($sale_price_dates_to) . '" placeholder="' . _x('To…', 'placeholder', 'woocommerce') . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> <a href="#" class="cancel_sale_schedule">' . __('Cancel', 'woocommerce') . '</a> <img class="help_tip" style="margin-top: 21px;" data-tip="' . __('The sale will end at the beginning of the set date.', 'woocommerce') . '" src="' . esc_url(WC()->plugin_url()) . '/assets/images/help.png" height="16" width="16" /> </p>'; do_action('woocommerce_product_options_pricing'); echo '</div>'; echo '<div class="options_group show_if_downloadable">'; ?> <div class="form-field downloadable_files"> <label><?php _e('Downloadable Files', 'woocommerce'); ?> :</label> <table class="widefat"> <thead> <tr> <th class="sort"> </th> <th><?php _e('Name', 'woocommerce'); ?> <span class="tips" data-tip="<?php _e('This is the name of the download shown to the customer.', 'woocommerce'); ?> ">[?]</span></th> <th colspan="2"><?php _e('File URL', 'woocommerce'); ?> <span class="tips" data-tip="<?php _e('This is the URL or absolute path to the file which customers will get access to. URLs entered here should already be encoded.', 'woocommerce'); ?> ">[?]</span></th> <th> </th> </tr> </thead> <tbody> <?php $downloadable_files = get_post_meta($post->ID, '_downloadable_files', true); if ($downloadable_files) { foreach ($downloadable_files as $key => $file) { include 'views/html-product-download.php'; } } ?> </tbody> <tfoot> <tr> <th colspan="5"> <a href="#" class="button insert" data-row="<?php $file = array('file' => '', 'name' => ''); ob_start(); include 'views/html-product-download.php'; echo esc_attr(ob_get_clean()); ?> "><?php _e('Add File', 'woocommerce'); ?> </a> </th> </tr> </tfoot> </table> </div> <?php // Download Limit woocommerce_wp_text_input(array('id' => '_download_limit', 'label' => __('Download Limit', 'woocommerce'), 'placeholder' => __('Unlimited', 'woocommerce'), 'description' => __('Leave blank for unlimited re-downloads.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Expirey woocommerce_wp_text_input(array('id' => '_download_expiry', 'label' => __('Download Expiry', 'woocommerce'), 'placeholder' => __('Never', 'woocommerce'), 'description' => __('Enter the number of days before a download link expires, or leave blank.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Download Type woocommerce_wp_select(array('id' => '_download_type', 'label' => __('Download Type', 'woocommerce'), 'description' => sprintf(__('Choose a download type - this controls the <a href="%s">schema</a>.', 'woocommerce'), 'http://schema.org/'), 'options' => array('' => __('Standard Product', 'woocommerce'), 'application' => __('Application/Software', 'woocommerce'), 'music' => __('Music', 'woocommerce')))); do_action('woocommerce_product_options_downloads'); echo '</div>'; if (wc_tax_enabled()) { echo '<div class="options_group show_if_simple show_if_external show_if_variable">'; // Tax woocommerce_wp_select(array('id' => '_tax_status', 'label' => __('Tax Status', 'woocommerce'), 'options' => array('taxable' => __('Taxable', 'woocommerce'), 'shipping' => __('Shipping only', 'woocommerce'), 'none' => _x('None', 'Tax status', 'woocommerce')))); $tax_classes = WC_Tax::get_tax_classes(); $classes_options = array(); $classes_options[''] = __('Standard', 'woocommerce'); if (!empty($tax_classes)) { foreach ($tax_classes as $class) { $classes_options[sanitize_title($class)] = esc_html($class); } } woocommerce_wp_select(array('id' => '_tax_class', 'label' => __('Tax Class', 'woocommerce'), 'options' => $classes_options)); do_action('woocommerce_product_options_tax'); echo '</div>'; } do_action('woocommerce_product_options_general_product_data'); ?> </div> <div id="inventory_product_data" class="panel woocommerce_options_panel"> <?php echo '<div class="options_group">'; if ('yes' == get_option('woocommerce_manage_stock')) { // manage stock woocommerce_wp_checkbox(array('id' => '_manage_stock', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Manage stock?', 'woocommerce'), 'description' => __('Enable stock management at product level', 'woocommerce'))); do_action('woocommerce_product_options_stock'); echo '<div class="stock_fields show_if_simple show_if_variable">'; // Stock woocommerce_wp_text_input(array('id' => '_stock', 'label' => __('Stock Qty', 'woocommerce'), 'desc_tip' => true, 'description' => __('Stock quantity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => 'any'), 'data_type' => 'stock')); // Backorders? woocommerce_wp_select(array('id' => '_backorders', 'label' => __('Allow Backorders?', 'woocommerce'), 'options' => array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce')), 'desc_tip' => true, 'description' => __('If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce'))); do_action('woocommerce_product_options_stock_fields'); echo '</div>'; } // Stock status woocommerce_wp_select(array('id' => '_stock_status', 'wrapper_class' => 'hide_if_variable', 'label' => __('Stock status', 'woocommerce'), 'options' => array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce')), 'desc_tip' => true, 'description' => __('Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'))); do_action('woocommerce_product_options_stock_status'); echo '</div>'; echo '<div class="options_group show_if_simple show_if_variable">'; // Individual product woocommerce_wp_checkbox(array('id' => '_sold_individually', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Sold Individually', 'woocommerce'), 'description' => __('Enable this to only allow one of this item to be bought in a single order', 'woocommerce'))); do_action('woocommerce_product_options_sold_individually'); echo '</div>'; do_action('woocommerce_product_options_inventory_product_data'); ?> </div> <div id="shipping_product_data" class="panel woocommerce_options_panel"> <?php echo '<div class="options_group">'; // Weight if (wc_product_weight_enabled()) { woocommerce_wp_text_input(array('id' => '_weight', 'label' => __('Weight', 'woocommerce') . ' (' . get_option('woocommerce_weight_unit') . ')', 'placeholder' => wc_format_localized_decimal(0), 'desc_tip' => 'true', 'description' => __('Weight in decimal form', 'woocommerce'), 'type' => 'text', 'data_type' => 'decimal')); } // Size fields if (wc_product_dimensions_enabled()) { ?> <p class="form-field dimensions_field"> <label for="product_length"><?php echo __('Dimensions', 'woocommerce') . ' (' . get_option('woocommerce_dimension_unit') . ')'; ?> </label> <span class="wrap"> <input id="product_length" placeholder="<?php _e('Length', 'woocommerce'); ?> " class="input-text wc_input_decimal" size="6" type="text" name="_length" value="<?php echo esc_attr(wc_format_localized_decimal(get_post_meta($thepostid, '_length', true))); ?> " /> <input placeholder="<?php _e('Width', 'woocommerce'); ?> " class="input-text wc_input_decimal" size="6" type="text" name="_width" value="<?php echo esc_attr(wc_format_localized_decimal(get_post_meta($thepostid, '_width', true))); ?> " /> <input placeholder="<?php _e('Height', 'woocommerce'); ?> " class="input-text wc_input_decimal last" size="6" type="text" name="_height" value="<?php echo esc_attr(wc_format_localized_decimal(get_post_meta($thepostid, '_height', true))); ?> " /> </span> <img class="help_tip" data-tip="<?php esc_attr_e('LxWxH in decimal form', 'woocommerce'); ?> " src="<?php echo esc_url(WC()->plugin_url()); ?> /assets/images/help.png" height="16" width="16" /> </p><?php } do_action('woocommerce_product_options_dimensions'); echo '</div>'; echo '<div class="options_group">'; // Shipping Class $classes = get_the_terms($thepostid, 'product_shipping_class'); if ($classes && !is_wp_error($classes)) { $current_shipping_class = current($classes)->term_id; } else { $current_shipping_class = ''; } $args = array('taxonomy' => 'product_shipping_class', 'hide_empty' => 0, 'show_option_none' => __('No shipping class', 'woocommerce'), 'name' => 'product_shipping_class', 'id' => 'product_shipping_class', 'selected' => $current_shipping_class, 'class' => 'select short'); ?> <p class="form-field dimensions_field"><label for="product_shipping_class"><?php _e('Shipping class', 'woocommerce'); ?> </label> <?php wp_dropdown_categories($args); ?> <img class="help_tip" data-tip="<?php esc_attr_e('Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce'); ?> " src="<?php echo esc_url(WC()->plugin_url()); ?> /assets/images/help.png" height="16" width="16" /></p><?php do_action('woocommerce_product_options_shipping'); echo '</div>'; ?> </div> <div id="product_attributes" class="panel wc-metaboxes-wrapper"> <div class="product_attributes wc-metaboxes"> <?php global $wc_product_attributes; // Array of defined attribute taxonomies $attribute_taxonomies = wc_get_attribute_taxonomies(); // Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set $attributes = maybe_unserialize(get_post_meta($thepostid, '_product_attributes', true)); // Output All Set Attributes if (!empty($attributes)) { $attribute_keys = array_keys($attributes); $attribute_total = sizeof($attribute_keys); for ($i = 0; $i < $attribute_total; $i++) { $attribute = $attributes[$attribute_keys[$i]]; $position = empty($attribute['position']) ? 0 : absint($attribute['position']); $taxonomy = ''; $metabox_class = array(); if ($attribute['is_taxonomy']) { $taxonomy = $attribute['name']; if (!taxonomy_exists($taxonomy)) { continue; } $attribute_taxonomy = $wc_product_attributes[$taxonomy]; $metabox_class[] = 'taxonomy'; $metabox_class[] = $taxonomy; $attribute_label = wc_attribute_label($taxonomy); } else { $attribute_label = apply_filters('woocommerce_attribute_label', $attribute['name'], $attribute['name']); } include 'views/html-product-attribute.php'; } } ?> </div> <p class="toolbar"> <button type="button" class="button button-primary add_attribute"><?php _e('Add', 'woocommerce'); ?> </button> <select name="attribute_taxonomy" class="attribute_taxonomy"> <option value=""><?php _e('Custom product attribute', 'woocommerce'); ?> </option> <?php if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $attribute_taxonomy_name = wc_attribute_taxonomy_name($tax->attribute_name); $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; echo '<option value="' . esc_attr($attribute_taxonomy_name) . '">' . esc_html($label) . '</option>'; } } ?> </select> <button type="button" class="button save_attributes"><?php _e('Save attributes', 'woocommerce'); ?> </button> </p> <?php do_action('woocommerce_product_options_attributes'); ?> </div> <div id="linked_product_data" class="panel woocommerce_options_panel"> <div class="options_group"> <p class="form-field"> <label for="upsell_ids"><?php _e('Up-Sells', 'woocommerce'); ?> </label> <input type="hidden" class="wc-product-search" style="width: 50%;" id="upsell_ids" name="upsell_ids" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> " data-action="woocommerce_json_search_products" data-multiple="true" data-exclude="<?php echo intval($post->ID); ?> " data-selected="<?php $product_ids = array_filter(array_map('absint', (array) get_post_meta($post->ID, '_upsell_ids', true))); $json_ids = array(); foreach ($product_ids as $product_id) { $product = wc_get_product($product_id); if (is_object($product)) { $json_ids[$product_id] = wp_kses_post(html_entity_decode($product->get_formatted_name())); } } echo esc_attr(json_encode($json_ids)); ?> " value="<?php echo implode(',', array_keys($json_ids)); ?> " /> <img class="help_tip" data-tip='<?php _e('Up-sells are products which you recommend instead of the currently viewed product, for example, products that are more profitable or better quality or more expensive.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /> </p> <p class="form-field"> <label for="crosssell_ids"><?php _e('Cross-Sells', 'woocommerce'); ?> </label> <input type="hidden" class="wc-product-search" style="width: 50%;" id="crosssell_ids" name="crosssell_ids" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> " data-action="woocommerce_json_search_products" data-multiple="true" data-exclude="<?php echo intval($post->ID); ?> " data-selected="<?php $product_ids = array_filter(array_map('absint', (array) get_post_meta($post->ID, '_crosssell_ids', true))); $json_ids = array(); foreach ($product_ids as $product_id) { $product = wc_get_product($product_id); if (is_object($product)) { $json_ids[$product_id] = wp_kses_post(html_entity_decode($product->get_formatted_name())); } } echo esc_attr(json_encode($json_ids)); ?> " value="<?php echo implode(',', array_keys($json_ids)); ?> " /> <img class="help_tip" data-tip='<?php _e('Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /> </p> </div> <div class="options_group grouping show_if_simple show_if_external"> <p class="form-field"> <label for="parent_id"><?php _e('Grouping', 'woocommerce'); ?> </label> <input type="hidden" class="wc-product-search" style="width: 50%;" id="parent_id" name="parent_id" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> " data-action="woocommerce_json_search_grouped_products" data-allow_clear="true" data-multiple="false" data-exclude="<?php echo intval($post->ID); ?> " data-selected="<?php $parent_id = absint($post->post_parent); if ($parent_id) { $parent = wc_get_product($parent_id); if (is_object($parent)) { $parent_title = wp_kses_post(html_entity_decode($parent->get_formatted_name())); } echo esc_attr($parent_title); } ?> " value="<?php echo $parent_id ? $parent_id : ''; ?> " /> <img class="help_tip" data-tip='<?php _e('Set this option to make this product part of a grouped product.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /> </p> <?php woocommerce_wp_hidden_input(array('id' => 'previous_parent_id', 'value' => absint($post->post_parent))); do_action('woocommerce_product_options_grouping'); ?> </div> <?php do_action('woocommerce_product_options_related'); ?> </div> <div id="advanced_product_data" class="panel woocommerce_options_panel"> <div class="options_group hide_if_external"> <?php // Purchase note woocommerce_wp_textarea_input(array('id' => '_purchase_note', 'label' => __('Purchase Note', 'woocommerce'), 'desc_tip' => 'true', 'description' => __('Enter an optional note to send the customer after purchase.', 'woocommerce'))); ?> </div> <div class="options_group"> <?php // menu_order woocommerce_wp_text_input(array('id' => 'menu_order', 'label' => __('Menu order', 'woocommerce'), 'desc_tip' => 'true', 'description' => __('Custom ordering position.', 'woocommerce'), 'value' => intval($post->menu_order), 'type' => 'number', 'custom_attributes' => array('step' => '1'))); ?> </div> <div class="options_group reviews"> <?php woocommerce_wp_checkbox(array('id' => 'comment_status', 'label' => __('Enable reviews', 'woocommerce'), 'cbvalue' => 'open', 'value' => esc_attr($post->comment_status))); do_action('woocommerce_product_options_reviews'); ?> </div> <?php do_action('woocommerce_product_options_advanced'); ?> </div> <?php self::output_variations(); do_action('woocommerce_product_data_panels'); do_action('woocommerce_product_write_panels'); // _deprecated ?> <div class="clear"></div> </div> <?php }
/** * Layered Nav Init */ public function layered_nav_init() { if (is_active_widget(false, false, 'woocommerce_layered_nav', true) && !is_admin()) { global $_chosen_attributes; $_chosen_attributes = array(); $attribute_taxonomies = wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $attribute = wc_sanitize_taxonomy_name($tax->attribute_name); $taxonomy = wc_attribute_taxonomy_name($attribute); $name = 'filter_' . $attribute; $query_type_name = 'query_type_' . $attribute; if (!empty($_GET[$name]) && taxonomy_exists($taxonomy)) { $_chosen_attributes[$taxonomy]['terms'] = explode(',', $_GET[$name]); if (empty($_GET[$query_type_name]) || !in_array(strtolower($_GET[$query_type_name]), array('and', 'or'))) { $_chosen_attributes[$taxonomy]['query_type'] = apply_filters('woocommerce_layered_nav_default_query_type', 'and'); } else { $_chosen_attributes[$taxonomy]['query_type'] = strtolower($_GET[$query_type_name]); } } } } add_filter('loop_shop_post_in', array($this, 'layered_nav_query')); } }
/** * 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 ''; }
public function product_attribute_filter_param($settings, $value) { if (!defined('WOOCOMMERCE_VERSION')) { return ''; } $output = ''; $args = array('orderby' => 'name', 'hide_empty' => false); $filter_ids = explode(',', $value); $attributes = wc_get_attribute_taxonomies(); $output .= '<select id= "' . $settings['param_name'] . '" multiple="multiple" data-placeholder="' . __('Select Attibute Filter', 'sitesao') . '" class="dh-product-attribute-filter dh-chosen-multiple-select dh-chosen-select wpb_vc_param_value wpb-input wpb-select ' . $settings['param_name'] . ' ' . $settings['type'] . '">'; if (!empty($attributes)) { foreach ($attributes as $attr) { if (taxonomy_exists(wc_attribute_taxonomy_name($attr->attribute_name))) { if ($name = wc_attribute_taxonomy_name($attr->attribute_name)) { $terms = get_terms($name, $args); if (!empty($terms)) { foreach ($terms as $term) { $v = $term->slug; $output .= '<option data-attr="' . esc_attr($name) . '" value="' . esc_attr($v) . '"' . selected(in_array($v, $filter_ids), true, false) . '>' . esc_html($term->name) . '</option>'; } } } } } } $output .= '</select>'; $output .= '<input id= "' . $settings['param_name'] . '" type="hidden" class="wpb_vc_param_value wpb-textinput" name="' . $settings['param_name'] . '" value="' . $value . '" />'; return $output; }