当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Product::get_attribute方法代码示例

本文整理汇总了PHP中WC_Product::get_attribute方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_attribute方法的具体用法?PHP WC_Product::get_attribute怎么用?PHP WC_Product::get_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Product的用法示例。


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

示例1: filter_custom_fields

 /**
  * Add woo attributes to a custom field with the same name
  *
  * @param $custom_fields
  * @param $post_id
  *
  * @return mixed
  */
 public function filter_custom_fields($custom_fields, $post_id)
 {
     if (!isset($custom_fields)) {
         $custom_fields = array();
     }
     // Get the product correponding to this post
     $product = new WC_Product($post_id);
     foreach ($product->get_attributes() as $attribute) {
         //$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
         // Remove the eventual 'pa_' prefix from the attribute name
         $attribute_name = $attribute['name'];
         if (substr($attribute_name, 0, 3) == 'pa_') {
             $attribute_name = substr($attribute_name, 3, strlen($attribute_name));
         }
         $custom_fields[$attribute_name] = explode(',', $product->get_attribute($attribute['name']));
     }
     return $custom_fields;
 }
开发者ID:zelle7,项目名称:wpsolr-search-engine,代码行数:26,代码来源:plugin-woocommerce.php

示例2: get_attributes

 /**
  * Get the attributes for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_attributes($product)
 {
     $attributes = array();
     if ($product->is_type('variation')) {
         // variation attributes
         foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
             // taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
             $attributes[] = array('name' => wc_attribute_label(str_replace('attribute_', '', $attribute_name)), 'slug' => str_replace('attribute_', '', str_replace('pa_', '', $attribute_name)), 'option' => $attribute);
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             // taxonomy-based attributes are comma-separated, others are pipe (|) separated
             if ($attribute['is_taxonomy']) {
                 $options = explode(',', $product->get_attribute($attribute['name']));
             } else {
                 $options = explode('|', $product->get_attribute($attribute['name']));
             }
             $attributes[] = array('name' => wc_attribute_label($attribute['name']), 'slug' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', $options));
         }
     }
     return $attributes;
 }
开发者ID:haltaction,项目名称:woocommerce,代码行数:29,代码来源:class-wc-api-products.php

示例3: get_product_from_post


//.........这里部分代码省略.........
                 }
             }
         }
     } catch (Exception $e) {
     }
     $acf_fields = array();
     try {
         if (class_exists('acf') && function_exists('get_field')) {
             $all_acf_fields = get_option('wcis_acf_fields');
             if (is_array($all_acf_fields)) {
                 foreach ($all_acf_fields as $acf_field_name) {
                     $acf_field_value = get_field($acf_field_name, $post_id);
                     if ($acf_field_value) {
                         $acf_fields[$acf_field_name] = $acf_field_value;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
     try {
         $variable = new WC_Product_Variable($post_id);
         $variations = $variable->get_available_variations();
         $variations_sku = '';
         if (!empty($variations)) {
             foreach ($variations as $variation) {
                 if ($product->get_sku() != $variation['sku']) {
                     $variations_sku .= $variation['sku'] . ' ';
                 }
             }
         }
         $send_product['variations_sku'] = $variations_sku;
         $all_attributes = $product->get_attributes();
         $attributes = array();
         if (!empty($all_attributes)) {
             foreach ($all_attributes as $attr_mame => $value) {
                 if ($all_attributes[$attr_mame]['is_taxonomy']) {
                     if (!$woocommerce_ver_below_2_1) {
                         $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names'));
                     } else {
                         $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names');
                     }
                 } else {
                     $attributes[$attr_mame] = $product->get_attribute($attr_mame);
                 }
             }
         }
         $send_product['attributes'] = $attributes;
         $send_product['total_variable_stock'] = $variable->get_total_stock();
         try {
             if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
                 if (function_exists('wc_get_product')) {
                     $original_product = wc_get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             } else {
                 if (function_exists('get_product')) {
                     $original_product = get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
开发者ID:booklein,项目名称:wpbookle,代码行数:67,代码来源:wcis_plugin.php

示例4: get_attributes

 /**
  * Get the attributes for a product or product variation.
  *
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 protected function get_attributes($product)
 {
     $attributes = array();
     if ($product->is_type('variation')) {
         // Variation attributes.
         foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
             $name = str_replace('attribute_', '', $attribute_name);
             // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
             if (0 === strpos($attribute_name, 'attribute_pa_')) {
                 $attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $attribute);
             } else {
                 $attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $name), 'option' => $attribute);
             }
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             // Taxonomy-based attributes are comma-separated, others are pipe (|) separated.
             if ($attribute['is_taxonomy']) {
                 $attributes[] = array('id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name($attribute['name']) : 0, 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', explode(',', $product->get_attribute($attribute['name']))));
             } else {
                 $attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', explode('|', $product->get_attribute($attribute['name']))));
             }
         }
     }
     return $attributes;
 }
开发者ID:seriusokhatsky,项目名称:woocommerce,代码行数:32,代码来源:class-wc-rest-products-controller.php


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