• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wc_attribute_taxonomy_name_by_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wc_attribute_taxonomy_name_by_id函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_attribute_taxonomy_name_by_id函数的具体用法?PHP wc_attribute_taxonomy_name_by_id怎么用?PHP wc_attribute_taxonomy_name_by_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wc_attribute_taxonomy_name_by_id函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_taxonomy

 /**
  * Get taxonomy.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return int|WP_Error
  */
 protected function get_taxonomy($request)
 {
     // Check if taxonomy is defined.
     // Prevents check for attribute taxonomy more than one time for each query.
     if ('' !== $this->taxonomy) {
         return $this->taxonomy;
     }
     if (!empty($request['attribute_id'])) {
         $taxonomy = wc_attribute_taxonomy_name_by_id((int) $request['attribute_id']);
         $this->taxonomy = $taxonomy;
     }
     return $this->taxonomy;
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:19,代码来源:abstract-wc-rest-terms-controller.php


示例2: delete_product_attribute_term

 /**
  * Delete a product attribute term.
  *
  * @since  2.5.0
  * @param int $attribute_id Attribute ID.
  * @param int $id the product attribute ID.
  * @return array
  */
 public function delete_product_attribute_term($attribute_id, $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_term', __('You do not have permission to delete product attribute terms', 'woocommerce'), 401);
         }
         $taxonomy = wc_attribute_taxonomy_name_by_id($attribute_id);
         if (!$taxonomy) {
             throw new WC_API_Exception('woocommerce_api_invalid_product_attribute_id', __('A product attribute with the provided ID could not be found', 'woocommerce'), 404);
         }
         $id = absint($id);
         $term = wp_delete_term($id, $taxonomy);
         if (!$term) {
             throw new WC_API_Exception('woocommerce_api_cannot_delete_product_attribute_term', sprintf(__('This %s cannot be deleted', 'woocommerce'), 'product_attribute_term'), 500);
         } else {
             if (is_wp_error($term)) {
                 throw new WC_API_Exception('woocommerce_api_cannot_delete_product_attribute_term', $term->get_error_message(), 400);
             }
         }
         do_action('woocommerce_api_delete_product_attribute_term', $id, $this);
         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()));
     }
 }
开发者ID:johnulist,项目名称:woocommerce,代码行数:35,代码来源:class-wc-api-products.php


示例3: save_variations_data


//.........这里部分代码省略.........
         }
         // Downloads.
         if ('yes' === $is_downloadable) {
             // Downloadable files.
             if (isset($variation['downloads']) && is_array($variation['downloads'])) {
                 $this->save_downloadable_files($product->id, $variation['downloads'], $variation_id);
             }
             // Download limit.
             if (isset($variation['download_limit'])) {
                 update_post_meta($variation_id, '_download_limit', -1 === $variation['download_limit'] ? '' : absint($variation['download_limit']));
             }
             // Download expiry.
             if (isset($variation['download_expiry'])) {
                 update_post_meta($variation_id, '_download_expiry', -1 === $variation['download_expiry'] ? '' : absint($variation['download_expiry']));
             }
         } else {
             update_post_meta($variation_id, '_download_limit', '');
             update_post_meta($variation_id, '_download_expiry', '');
             update_post_meta($variation_id, '_downloadable_files', '');
         }
         // Description.
         if (isset($variation['description'])) {
             update_post_meta($variation_id, '_variation_description', wp_kses_post($variation['description']));
         }
         // Update taxonomies.
         if (isset($variation['attributes'])) {
             $updated_attribute_keys = array();
             foreach ($variation['attributes'] as $attribute) {
                 $attribute_id = 0;
                 $attribute_name = '';
                 // Check ID for global attributes or name for product attributes.
                 if (!empty($attribute['id'])) {
                     $attribute_id = absint($attribute['id']);
                     $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
                 } elseif (!empty($attribute['name'])) {
                     $attribute_name = sanitize_title($attribute['name']);
                 }
                 if (!$attribute_id && !$attribute_name) {
                     continue;
                 }
                 if (isset($attributes[$attribute_name])) {
                     $_attribute = $attributes[$attribute_name];
                 }
                 if (isset($_attribute['is_variation']) && $_attribute['is_variation']) {
                     $_attribute_key = 'attribute_' . sanitize_title($_attribute['name']);
                     $updated_attribute_keys[] = $_attribute_key;
                     if (isset($_attribute['is_taxonomy']) && $_attribute['is_taxonomy']) {
                         // Don't use wc_clean as it destroys sanitized characters
                         $_attribute_value = isset($attribute['option']) ? sanitize_title(stripslashes($attribute['option'])) : '';
                     } else {
                         $_attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
                     }
                     update_post_meta($variation_id, $_attribute_key, $_attribute_value);
                 }
             }
             // Remove old taxonomies attributes so data is kept up to date - first get attribute key names.
             $delete_attribute_keys = $wpdb->get_col($wpdb->prepare("SELECT meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE 'attribute_%%' AND meta_key NOT IN ( '" . implode("','", $updated_attribute_keys) . "' ) AND post_id = %d;", $variation_id));
             foreach ($delete_attribute_keys as $key) {
                 delete_post_meta($variation_id, $key);
             }
         }
         do_action('woocommerce_rest_save_product_variation', $variation_id, $menu_order, $variation);
     }
     // Update parent if variable so price sorting works and stays in sync with the cheapest child.
     WC_Product_Variable::sync($product->id);
     // Update default attributes options setting.
开发者ID:pelmered,项目名称:woocommerce,代码行数:67,代码来源:class-wc-rest-products-controller.php


示例4: save_variations_data


//.........这里部分代码省略.........
         if ($variation->get_downloadable()) {
             // Downloadable files.
             if (isset($data['downloads']) && is_array($data['downloads'])) {
                 $variation = $this->save_downloadable_files($variation, $data['downloads']);
             }
             // Download limit.
             if (isset($data['download_limit'])) {
                 $variation->set_download_limit($data['download_limit']);
             }
             // Download expiry.
             if (isset($data['download_expiry'])) {
                 $variation->set_download_expiry($data['download_expiry']);
             }
         }
         // Shipping data.
         $variation = $this->save_product_shipping_data($variation, $data);
         // Stock handling.
         if (isset($data['manage_stock'])) {
             $variation->set_manage_stock($data['manage_stock']);
         }
         if (isset($data['in_stock'])) {
             $variation->set_stock_status(true === $data['in_stock'] ? 'instock' : 'outofstock');
         }
         if (isset($data['backorders'])) {
             $variation->set_backorders($data['backorders']);
         }
         if ($variation->get_manage_stock()) {
             if (isset($data['stock_quantity'])) {
                 $variation->set_stock_quantity($data['stock_quantity']);
             } elseif (isset($data['inventory_delta'])) {
                 $stock_quantity = wc_stock_amount($variation->get_stock_amount());
                 $stock_quantity += wc_stock_amount($data['inventory_delta']);
                 $variation->set_stock_quantity($stock_quantity);
             }
         } else {
             $variation->set_backorders('no');
             $variation->set_stock_quantity('');
         }
         // Regular Price.
         if (isset($data['regular_price'])) {
             $variation->set_regular_price($data['regular_price']);
         }
         // Sale Price.
         if (isset($data['sale_price'])) {
             $variation->set_sale_price($data['sale_price']);
         }
         if (isset($data['date_on_sale_from'])) {
             $variation->set_date_on_sale_from($data['date_on_sale_from']);
         }
         if (isset($data['date_on_sale_to'])) {
             $variation->set_date_on_sale_to($data['date_on_sale_to']);
         }
         // Tax class.
         if (isset($data['tax_class'])) {
             $variation->set_tax_class($data['tax_class']);
         }
         // Description.
         if (isset($data['description'])) {
             $variation->set_description(wp_kses_post($data['description']));
         }
         // Update taxonomies.
         if (isset($data['attributes'])) {
             $attributes = array();
             $parent_attributes = $product->get_attributes();
             foreach ($data['attributes'] as $attribute) {
                 $attribute_id = 0;
                 $attribute_name = '';
                 // Check ID for global attributes or name for product attributes.
                 if (!empty($attribute['id'])) {
                     $attribute_id = absint($attribute['id']);
                     $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
                 } elseif (!empty($attribute['name'])) {
                     $attribute_name = sanitize_title($attribute['name']);
                 }
                 if (!$attribute_id && !$attribute_name) {
                     continue;
                 }
                 if (!isset($parent_attributes[$attribute_name]) || !$parent_attributes[$attribute_name]->get_variation()) {
                     continue;
                 }
                 $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name());
                 $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
                 if ($parent_attributes[$attribute_name]->is_taxonomy()) {
                     // If dealing with a taxonomy, we need to get the slug from the name posted to the API.
                     $term = get_term_by('name', $attribute_value, $attribute_name);
                     if ($term && !is_wp_error($term)) {
                         $attribute_value = $term->slug;
                     } else {
                         $attribute_value = sanitize_title($attribute_value);
                     }
                 }
                 $attributes[$attribute_key] = $attribute_value;
             }
             $variation->set_attributes($attributes);
         }
         $variation->save();
         do_action('woocommerce_rest_save_product_variation', $variation->get_id(), $menu_order, $data);
     }
     return true;
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:101,代码来源:class-wc-rest-products-controller.php


示例5: get_taxonomy

 /**
  * Get attribute name.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return string
  */
 protected function get_taxonomy($request)
 {
     if ('' !== $this->attribute) {
         return $this->attribute;
     }
     if ($request['id']) {
         $name = wc_attribute_taxonomy_name_by_id((int) $request['id']);
         $this->attribute = $name;
     }
     return $this->attribute;
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:17,代码来源:class-wc-rest-product-attributes-controller.php



注:本文中的wc_attribute_taxonomy_name_by_id函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wc_cart_totals_coupon_html函数代码示例发布时间:2022-05-23
下一篇:
PHP wc_attribute_taxonomy_name函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap