function yith_vendors_update_db_1_0_1() { $vendors_db_option = get_option('yith_product_vendors_db_version', '1.0.0'); if ($vendors_db_option && version_compare($vendors_db_option, '1.0.1', '<')) { global $wpdb; $sql = "SELECT woocommerce_term_id as vendor_id, meta_value as user_id\r\n FROM {$wpdb->woocommerce_termmeta} as wtm\r\n WHERE wtm.meta_key = %s\r\n AND woocommerce_term_id IN (\r\n SELECT DISTINCT term_id as vendor_id\r\n FROM {$wpdb->term_taxonomy} as tt\r\n WHERE tt.taxonomy = %s\r\n )"; $results = $wpdb->get_results($wpdb->prepare($sql, 'owner', YITH_Vendors()->get_taxonomy_name())); foreach ($results as $result) { $user = get_user_by('id', $result->user_id); if ($user) { update_woocommerce_term_meta($result->vendor_id, 'registration_date', get_date_from_gmt($user->user_registered)); update_woocommerce_term_meta($result->vendor_id, 'registration_date_gmt', $user->user_registered); if (defined('YITH_WPV_PREMIUM')) { $user->add_cap('view_woocommerce_reports'); } } } update_option('yith_product_vendors_db_version', '1.0.1'); } }
/** * Update term meta fields. * * @param WP_Term $term * @param WP_REST_Request $request * @return bool|WP_Error */ protected function update_term_meta_fields($term, $request) { $id = (int) $term->term_id; update_woocommerce_term_meta($id, 'display_type', $request['display']); if (!empty($request['image'])) { $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image'])); if (is_wp_error($upload)) { return $upload; } $image_id = wc_rest_set_uploaded_image_as_attachment($upload); // Check if image_id is a valid image attachment before updating the term meta. if ($image_id && wp_attachment_is_image($image_id)) { update_woocommerce_term_meta($id, 'thumbnail_id', $image_id); } } return true; }
/** * Edit a product category. * * @since 2.5.0 * @param int $id Product category term ID * @param array $data Posted data * @return array|WP_Error Product category if succeed, otherwise WP_Error * will be returned */ public function edit_product_category($id, $data) { global $wpdb; try { if (!isset($data['product_category'])) { throw new WC_API_Exception('woocommerce_api_missing_product_category', sprintf(__('No %1$s data specified to edit %1$s', 'woocommerce'), 'product_category'), 400); } $id = absint($id); $data = $data['product_category']; // Check permissions. if (!current_user_can('manage_product_terms')) { throw new WC_API_Exception('woocommerce_api_user_cannot_edit_product_category', __('You do not have permission to edit product categories', 'woocommerce'), 401); } $data = apply_filters('woocommerce_api_edit_product_category_data', $data, $this); $category = $this->get_product_category($id); if (is_wp_error($category)) { return $category; } $display_type = ''; if (isset($data['display'])) { $display_type = $data['display']; unset($data['display']); } if (isset($data['image'])) { // If value of image is numeric, assume value as image_id. $image = $data['image']; if (is_numeric($image)) { $image_id = absint($image); } else { if (!empty($image)) { $upload = $this->upload_product_image(esc_url_raw($image)); $image_id = $this->set_product_category_image_as_attachment($upload); } } // In case client supplies invalid image or wants to unset category // image. if (!wp_attachment_is_image($image_id)) { $image_id = ''; } unset($data['image']); } $update = wp_update_term($id, 'product_cat', $data); if (is_wp_error($update)) { throw new WC_API_Exception('woocommerce_api_cannot_edit_product_catgory', __('Could not edit the category', 'woocommerce'), 400); } if (!empty($display_type)) { update_woocommerce_term_meta($update['term_taxonomy_id'], 'display_type', esc_attr($display_type)); } if (isset($image_id)) { update_woocommerce_term_meta($update['term_taxonomy_id'], 'thumbnail_id', $image_id); } do_action('woocommerce_api_edit_product_category', $id, $data); return $this->get_product_category($id); } catch (WC_API_Exception $e) { return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); } }
/** * save_category_fields function. * * @param mixed $term_id Term ID being saved * @param mixed $tt_id * @param string $taxonomy */ public function save_category_fields($term_id, $tt_id = '', $taxonomy = '') { if (isset($_POST['display_type']) && 'product_cat' === $taxonomy) { update_woocommerce_term_meta($term_id, 'display_type', esc_attr($_POST['display_type'])); } if (isset($_POST['product_cat_thumbnail_id']) && 'product_cat' === $taxonomy) { update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['product_cat_thumbnail_id'])); } }
/** * dhwc_brand_thumbnail_save function. * * @access public * @param mixed $term_id Term ID being saved * @param mixed $tt_id * @param mixed $taxonomy Taxonomy of the term being saved * @return void */ function dhwc_brand_thumbnail_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['product_brand_thumbnail_id'])) { update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['product_brand_thumbnail_id'])); } }
/** * save_fields function * saves the form fields to the term meta * * @see WC_Admin_Taxonomies * * @access public * @param int $term_id Id of the term that's being updated * @param int $tt_id I don't know * @param string $taxonomy Slug of the taxonomy type being updated * @return void */ public function save_fields($term_id, $tt_id = '', $taxonomy = '') { if (isset($_POST['wc_category_diagram_id']) && 'product_cat' === $taxonomy) { update_woocommerce_term_meta($term_id, 'wc_category_diagram_id', esc_attr($_POST['wc_category_diagram_id'])); } if (isset($_POST['wc_category_diagram_text']) && 'product_cat' === $taxonomy) { update_woocommerce_term_meta($term_id, 'wc_category_diagram_text', esc_attr($_POST['wc_category_diagram_text'])); } }
/** * Function for recounting product terms, ignoring hidden products. * * @access public * @param mixed $term * @param mixed $taxonomy * @return void */ function _woocommerce_term_recount($terms, $taxonomy, $callback = true, $terms_are_term_taxonomy_ids = true) { global $wpdb; // Standard callback if ($callback) { _update_post_term_count($terms, $taxonomy); } // Stock query if (get_option('woocommerce_hide_out_of_stock_items') == 'yes') { $stock_join = "LEFT JOIN {$wpdb->postmeta} AS meta_stock ON posts.ID = meta_stock.post_id"; $stock_query = "\n\t\tAND (\n\t\t\tmeta_stock.meta_key = '_stock_status'\n\t\t\tAND\n\t\t\tmeta_stock.meta_value = 'instock'\n\t\t)"; } else { $stock_query = $stock_join = ''; } // Main query $count_query = $wpdb->prepare("\n\t\tSELECT COUNT( DISTINCT posts.ID ) FROM {$wpdb->posts} as posts\n\n\t\tLEFT JOIN {$wpdb->postmeta} AS meta_visibility ON posts.ID = meta_visibility.post_id\n\t\tLEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID\n\t\tLEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )\n\t\tLEFT JOIN {$wpdb->terms} AS term USING( term_id )\n\t\t{$stock_join}\n\n\t\tWHERE \tposts.post_status \t= 'publish'\n\t\tAND \tposts.post_type \t= 'product'\n\t\tAND \t(\n\t\t\tmeta_visibility.meta_key = '_visibility'\n\t\t\tAND\n\t\t\tmeta_visibility.meta_value IN ( 'visible', 'catalog' )\n\t\t)\n\t\tAND \ttax.taxonomy\t= %s\n\t\t{$stock_query}\n\t", $taxonomy->name); // Store terms + counts here $term_counts = array(); $counted_terms = array(); $maybe_count_parents = array(); // Pre-process term taxonomy ids if ($terms_are_term_taxonomy_ids) { $term_ids = array(); foreach ((array) $terms as $term) { $the_term = $wpdb->get_row("SELECT term_id, parent FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = {$term} AND taxonomy = '{$taxonomy->name}'"); $term_ids[$the_term->term_id] = $the_term->parent; } $terms = $term_ids; } // Count those terms! foreach ((array) $terms as $term_id => $parent_id) { $term_ids = array(); if (is_taxonomy_hierarchical($taxonomy->name)) { // Grab the parents to count later $parent = $parent_id; while (!empty($parent) && $parent > 0) { $maybe_count_parents[] = $parent; $parent_term = get_term_by('id', $parent, $taxonomy->name); if ($parent_term) { $parent = $parent_term->parent; } else { $parent = 0; } } // We need to get the $term's hierarchy so we can count its children too $term_ids = get_term_children($term_id, $taxonomy->name); } $term_ids[] = absint($term_id); // Generate term query $term_query = 'AND term.term_id IN ( ' . implode(',', $term_ids) . ' )'; // Get the count $count = $wpdb->get_var($count_query . $term_query); update_woocommerce_term_meta($term_id, 'product_count_' . $taxonomy->name, absint($count)); $counted_terms[] = $term_id; } // Re-count parents if (is_taxonomy_hierarchical($taxonomy->name)) { $terms = array_diff($maybe_count_parents, $counted_terms); foreach ((array) $terms as $term) { $term_ids = get_term_children($term, $taxonomy->name); $term_ids[] = $term; // Generate term query $term_query = 'AND term.term_id IN ( ' . implode(',', $term_ids) . ' )'; // Get the count $count = $wpdb->get_var($count_query . $term_query); update_woocommerce_term_meta($term, 'product_count_' . $taxonomy->name, absint($count)); } } }
public function woocommerce_attribute_thumbnail_field_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['product_attribute_meta'])) { $metas = $_POST['product_attribute_meta']; if (isset($metas[$this->meta_key])) { $data = $metas[$this->meta_key]; $photo = isset($data['photo']) ? $data['photo'] : ''; $color = isset($data['color']) ? $data['color'] : ''; $type = isset($data['type']) ? $data['type'] : ''; update_woocommerce_term_meta($term_id, $taxonomy . '_' . $this->meta_key . '_type', $type); update_woocommerce_term_meta($term_id, $taxonomy . '_' . $this->meta_key . '_photo', $photo); update_woocommerce_term_meta($term_id, $taxonomy . '_' . $this->meta_key . '_color', $color); } } }
public function setData($dataId, $dataValue) { update_woocommerce_term_meta($dataId, $this->getOptionName(), $dataValue); }
function et_brands_fields_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['brand_thumbnail_id'])) { update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['brand_thumbnail_id'])); } delete_transient('wc_term_counts'); }
/** * Save the freight class * * @param int $term_id * @param int $tt_id * @param string $taxonomy */ public function save($term_id, $tt_id, $taxonomy) { if (isset($_POST['fedex_freight_class'])) { update_woocommerce_term_meta($term_id, 'fedex_freight_class', sanitize_text_field($_POST['fedex_freight_class'])); } }
function category_field_save($term_id, $tt_id, $taxonomy) { $restrictions_enabled = isset($_POST['_wc_restrictions']) ? $_POST['_wc_restrictions'] : false; if (empty($restrictions_enabled) || $restrictions_enabled == 'no-restriction-setting') { delete_woocommerce_term_meta($term_id, '_wc_restrictions'); delete_woocommerce_term_meta($term_id, '_wc_restrictions_allowed'); } else { update_woocommerce_term_meta($term_id, '_wc_restrictions', $restrictions_enabled); delete_woocommerce_term_meta($term_id, '_wc_restrictions_allowed'); if ($restrictions_enabled == 'restricted') { $restrictions = isset($_POST['wc_restrictions_allowed']) ? $_POST['wc_restrictions_allowed'] : array(''); foreach ($restrictions as $role) { add_woocommerce_term_meta($term_id, '_wc_restrictions_allowed', $role); } } } $restrictions_location_enabled = isset($_POST['_wc_restrictions_location']) ? $_POST['_wc_restrictions_location'] : false; if (empty($restrictions_location_enabled) || $restrictions_location_enabled == 'no-restriction-setting') { delete_woocommerce_term_meta($term_id, '_wc_restrictions_location'); delete_woocommerce_term_meta($term_id, '_wc_restrictions_locations'); } else { update_woocommerce_term_meta($term_id, '_wc_restrictions_location', $restrictions_location_enabled); delete_woocommerce_term_meta($term_id, '_wc_restrictions_locations'); if ($restrictions_location_enabled == 'restricted') { $restrictions = isset($_POST['wc_restrictions_locations']) ? $_POST['wc_restrictions_locations'] : array(''); foreach ($restrictions as $location) { add_woocommerce_term_meta($term_id, '_wc_restrictions_locations', $location); } } } }
/** * Save attribute field * * @access public * @since 1.0.0 */ public function attribute_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['term-value'])) { update_woocommerce_term_meta($term_id, $taxonomy . '_yith_wccl_value', $_POST['term-value']); } }
function trbl_sync_categories() { if (!wp_verify_nonce($_REQUEST['wcml_nonce'], 'trbl_sync_categories')) { die('Invalid nonce'); } $page = isset($_POST['page']) ? $_POST['page'] : 0; global $wpdb, $sitepress; $all_categories = $wpdb->get_results($wpdb->prepare("SELECT t.term_taxonomy_id,t.term_id FROM {$wpdb->term_taxonomy} AS t LEFT JOIN {$wpdb->prefix}icl_translations AS tr ON tr.element_id = t.term_taxonomy_id WHERE t.taxonomy = 'product_cat' AND tr.element_type = 'tax_product_cat' AND tr.source_language_code is NULL ORDER BY t.term_taxonomy_id LIMIT %d,5", $page * 5)); foreach ($all_categories as $category) { $trid = $sitepress->get_element_trid($category->term_taxonomy_id, 'tax_product_cat'); $translations = $sitepress->get_element_translations($trid, 'tax_product_cat'); $type = get_woocommerce_term_meta($category->term_id, 'display_type', true); $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true); foreach ($translations as $translation) { if ($translation->language_code != $sitepress->get_default_language()) { update_woocommerce_term_meta($translation->term_id, 'display_type', $type); update_woocommerce_term_meta($translation->term_id, 'thumbnail_id', icl_object_id($thumbnail_id, 'attachment', true, $translation->language_code)); } } } echo 1; die; }
function save($post_id) { $people = $this->_meta_box['people_fields']; foreach ($people as $people_field) { $key = $people_field['id']; if (!empty($_POST[$key])) { update_woocommerce_term_meta($post_id, $key, $_POST[$key]); } } foreach ($this->_meta_box['org_fields'] as $org_field) { $org_key = $org_field['id']; if (!empty($_POST[$org_key])) { update_woocommerce_term_meta($post_id, $org_key, $_POST[$org_key]); } } foreach ($this->_meta_box['events_fields'] as $event_field) { $event_key = $event_field['id']; if (!empty($_POST[$event_key])) { update_woocommerce_term_meta($post_id, $event_key, $_POST[$event_key]); } } foreach ($this->_meta_box['product_fields'] as $product_field) { $product_key = $product_field['id']; if (!empty($_POST[$product_key])) { update_woocommerce_term_meta($post_id, $product_key, $_POST[$product_key]); } } foreach ($this->_meta_box['music_fields'] as $music_field) { $music_key = $music_field['id']; if (!empty($_POST[$music_key])) { update_woocommerce_term_meta($post_id, $music_key, $_POST[$music_key]); } } foreach ($this->_meta_box['receipes_fields'] as $receipes_field) { $receipes_key = $receipes_field['id']; if (!empty($_POST[$receipes_key])) { update_woocommerce_term_meta($post_id, $receipes_key, $_POST[$receipes_key]); } } foreach ($this->_meta_box['software_fields'] as $software_field) { $software_key = $software_field['id']; if (!empty($_POST[$software_key])) { update_woocommerce_term_meta($post_id, $software_key, $_POST[$software_key]); } } foreach ($this->_meta_box['videos_fields'] as $videos_field) { $videos_key = $videos_field['id']; if (!empty($_POST[$videos_key])) { update_woocommerce_term_meta($post_id, $videos_key, $_POST[$videos_key]); } } $review = $this->_meta_box['review_fields']; foreach ($review as $review_fields) { $review_key = $review_fields['id']; if (!empty($_POST[$review_key])) { update_woocommerce_term_meta($post_id, $review_key, $_POST[$review_key]); } } $review_rating = $this->_meta_box['review_rating_fields']; foreach ($review_rating as $review_rating_fields) { $review_rating_key = $review_rating_fields['id']; if (!empty($_POST[$review_rating_key])) { update_woocommerce_term_meta($post_id, $review_rating_key, $_POST[$review_rating_key]); } } }
/** * Save the points earned / maximum discount fields * * @since 1.0 * @param int $term_id term ID being saved */ public function save_product_category_points_field($term_id) { // points earned if (isset($_POST['_wc_points_earned']) && '' !== $_POST['_wc_points_earned']) { update_woocommerce_term_meta($term_id, '_wc_points_earned', $_POST['_wc_points_earned']); } else { delete_woocommerce_term_meta($term_id, '_wc_points_earned'); } // max points discount if (isset($_POST['_wc_points_max_discount']) && '' !== $_POST['_wc_points_max_discount']) { update_woocommerce_term_meta($term_id, '_wc_points_max_discount', $_POST['_wc_points_max_discount']); } else { delete_woocommerce_term_meta($term_id, '_wc_points_max_discount'); } }
public function pf_attribute_image_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['pf_meta'])) { $metas = $_POST['pf_meta']; if (isset($metas[$this->pf_meta])) { $data = $metas[$this->pf_meta]; $photo = isset($data['photo']) ? $data['photo'] : ''; update_woocommerce_term_meta($term_id, $taxonomy . '_' . $this->pf_meta . '_photo', $photo); } } }
function save_yith_shop_vendor_metadata($term_id) { $idval = $_POST['tag_ID']; $meta_value = boilerclassp(); update_woocommerce_term_meta($idval, 'Beschreibungeditor', $_POST['yith_vendor_data1']['Beschreibungeditor']); update_woocommerce_term_meta($idval, 'regionto', $_POST['yith_vendor_data']['regionto']); foreach ($meta_value as $meta_b) { $metavlddd = new ADD_META_BOX1($meta_b); $metavlddd->save($idval); } }
/** * save_category_fields function. * * @access public * @param mixed $term_id Term ID being saved * @param mixed $tt_id * @param mixed $taxonomy Taxonomy of the term being saved * @return void */ public function save_category_fields($term_id, $tt_id, $taxonomy) { if (isset($_POST['display_type'])) { update_woocommerce_term_meta($term_id, 'display_type', esc_attr($_POST['display_type'])); } if (isset($_POST['product_cat_thumbnail_id'])) { update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['product_cat_thumbnail_id'])); } delete_transient('wc_term_counts'); }
/** * Save data function. */ public function save_data() { if (!$this->is_valid() || empty($this->_changed)) { return; } // save the property to change in the term $term_properties = array(); foreach ($this->_changed as $property => $value) { $value = !is_array($value) ? wc_clean($value) : $value; if (in_array($property, array('name', 'slug', 'description'))) { $term_properties[$property] = $value; } else { update_woocommerce_term_meta($this->id, $property, $value); } } // save the term data if (!empty($term_properties)) { wp_update_term($this->id, self::$taxonomy, $term_properties); } }
/** * Order term when created (put in position 0). * * @access public * @param mixed $term_id * @param mixed $tt_id * @param mixed $taxonomy * @return void */ function woocommerce_create_term($term_id, $tt_id = '', $taxonomy = '') { if (!$taxonomy == 'product_cat' && !strstr($taxonomy, 'pa_')) { return; } $meta_name = strstr($taxonomy, 'pa_') ? 'order_' . esc_attr($taxonomy) : 'order'; update_woocommerce_term_meta($term_id, $meta_name, 0); }
/** * Update term meta fields. * * @param WP_Term $term * @param WP_REST_Request $request * @return bool|WP_Error */ protected function update_term_meta_fields($term, $request) { $id = (int) $term->term_id; update_woocommerce_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']); update_woocommerce_term_meta($id, 'order', $request['menu_order']); if (!empty($request['image'])) { if (empty($request['image']['id']) && !empty($request['image']['src'])) { $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src'])); if (is_wp_error($upload)) { return $upload; } $image_id = wc_rest_set_uploaded_image_as_attachment($upload); } else { $image_id = absint($request['image']['id']); } // Check if image_id is a valid image attachment before updating the term meta. if ($image_id && wp_attachment_is_image($image_id)) { update_woocommerce_term_meta($id, 'thumbnail_id', $image_id); // Set the image alt. if (!empty($request['image']['alt'])) { update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt'])); } // Set the image title. if (!empty($request['image']['title'])) { wp_update_post(array('ID' => $image_id, 'post_title' => wc_clean($request['image']['title']))); } } } return true; }
/** * generate_term function * @access public * @return void */ public function generate_term() { global $WCMp; if (!isset($this->term_id)) { $term = wp_insert_term($this->user_data->user_login, $WCMp->taxonomy->taxonomy_name); if (!is_wp_error($term)) { update_user_meta($this->id, '_vendor_term_id', $term['term_id']); update_woocommerce_term_meta($term['term_id'], '_vendor_user_id', $this->id); } } }
/** * woocommerce_category_thumbnail_field_save function. * * @access public * @param mixed $term_id Term ID being saved * @param mixed $tt_id * @param mixed $taxonomy Taxonomy of the term being saved * @return void */ function woocommerce_category_thumbnail_field_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['product_cat_thumbnail_id'])) { update_woocommerce_term_meta($term_id, 'thumbnail_id', $_POST['product_cat_thumbnail_id']); } }
/** * Function for recounting product terms, ignoring hidden products. * * @param array $terms * @param string $taxonomy * @param boolean $callback * @param boolean $terms_are_term_taxonomy_ids */ function _wc_term_recount($terms, $taxonomy, $callback = true, $terms_are_term_taxonomy_ids = true) { global $wpdb; // Standard callback if ($callback) { _update_post_term_count($terms, $taxonomy); } // Stock query if (get_option('woocommerce_hide_out_of_stock_items') == 'yes') { $stock_join = "LEFT JOIN {$wpdb->postmeta} AS meta_stock ON posts.ID = meta_stock.post_id"; $stock_query = "\r\n\t\tAND meta_stock.meta_key = '_stock_status'\r\n\t\tAND meta_stock.meta_value = 'instock'\r\n\t\t"; } else { $stock_query = $stock_join = ''; } // Main query $count_query = "\r\n\t\tSELECT COUNT( DISTINCT posts.ID ) FROM {$wpdb->posts} as posts\r\n\t\tLEFT JOIN {$wpdb->postmeta} AS meta_visibility ON posts.ID = meta_visibility.post_id\r\n\t\tLEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID\r\n\t\tLEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )\r\n\t\tLEFT JOIN {$wpdb->terms} AS term USING( term_id )\r\n\t\tLEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id\r\n\t\t{$stock_join}\r\n\t\tWHERE \tpost_status = 'publish'\r\n\t\tAND \tpost_type \t= 'product'\r\n\t\tAND \tmeta_visibility.meta_key = '_visibility'\r\n\t\tAND \tmeta_visibility.meta_value IN ( 'visible', 'catalog' )\r\n\t\t{$stock_query}\r\n\t"; // Pre-process term taxonomy ids if (!$terms_are_term_taxonomy_ids) { // We passed in an array of TERMS in format id=>parent $terms = array_filter((array) array_keys($terms)); } else { // If we have term taxonomy IDs we need to get the term ID $term_taxonomy_ids = $terms; $terms = array(); foreach ($term_taxonomy_ids as $term_taxonomy_id) { $term = get_term_by('term_taxonomy_id', $term_taxonomy_id, $taxonomy->name); $terms[] = $term->term_id; } } // Exit if we have no terms to count if (!$terms) { return; } // Ancestors need counting if (is_taxonomy_hierarchical($taxonomy->name)) { foreach ($terms as $term_id) { $terms = array_merge($terms, get_ancestors($term_id, $taxonomy->name)); } } // Unique terms only $terms = array_unique($terms); // Count the terms foreach ($terms as $term_id) { $terms_to_count = array(absint($term_id)); if (is_taxonomy_hierarchical($taxonomy->name)) { // We need to get the $term's hierarchy so we can count its children too if (($children = get_term_children($term_id, $taxonomy->name)) && !is_wp_error($children)) { $terms_to_count = array_unique(array_map('absint', array_merge($terms_to_count, $children))); } } // Generate term query $term_query = 'AND term_id IN ( ' . implode(',', $terms_to_count) . ' )'; // Get the count $count = $wpdb->get_var($count_query . $term_query); // Update the count update_woocommerce_term_meta($term_id, 'product_count_' . $taxonomy->name, absint($count)); } delete_transient('wc_term_counts'); }
/** * Set the sort order of a term * * @param int $term_id * @param int $index * @param bool $recursive */ function woocommerce_set_term_order($term_id, $index, $taxonomy, $recursive = false) { global $wpdb; $term_id = (int) $term_id; $index = (int) $index; // Meta name if (strstr($taxonomy, 'pa_')) { $meta_name = 'order_' . esc_attr($taxonomy); } else { $meta_name = 'order'; } update_woocommerce_term_meta($term_id, $meta_name, $index); if (!$recursive) { return $index; } $children = get_terms($taxonomy, "parent={$term_id}&menu_order=ASC&hide_empty=0"); foreach ($children as $term) { $index++; $index = woocommerce_set_term_order($term->term_id, $index, $taxonomy, true); } return $index; }
/** * Return products in a given term, and cache value. * * To keep in sync, product_count will be cleared on "set_object_terms". * * @param int $term_id * @param string $taxonomy * @return array */ function wc_get_term_product_ids($term_id, $taxonomy) { $product_ids = get_woocommerce_term_meta($term_id, 'product_ids', true); if (false === $product_ids || !is_array($product_ids)) { $product_ids = get_objects_in_term($term_id, $taxonomy); update_woocommerce_term_meta($term_id, 'product_ids', $product_ids); } return $product_ids; }
public function kt_save_product_brand_fields($term_id, $tt_id = '', $taxonomy = '') { if (isset($_POST['product_brand_thumbnail_id']) && 'product_brand' === $taxonomy) { update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['product_brand_thumbnail_id'])); } }
function sf_product_cat_save_hero_image($term_id, $tt_id, $taxonomy) { if (isset($_POST['product_cat_hero_id'])) { update_woocommerce_term_meta($term_id, 'hero_id', absint($_POST['product_cat_hero_id'])); } }
/** * dhlookbook_lookbook_thumbnail_save function. * * @access public * @param mixed $term_id Term ID being saved * @param mixed $tt_id * @param mixed $taxonomy Taxonomy of the term being saved * @return void */ function dhlookbook_lookbook_thumbnail_save($term_id, $tt_id, $taxonomy) { if (isset($_POST['product_lookbook_thumbnail_id'])) { update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['product_lookbook_thumbnail_id'])); } if (isset($_POST['lookbook_thumbnail_align'])) { update_woocommerce_term_meta($term_id, 'thumbnail_align', sanitize_title($_POST['lookbook_thumbnail_align'])); } if (isset($_POST['small_title'])) { update_woocommerce_term_meta($term_id, 'small_title', $_POST['small_title']); } }