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


PHP WC_Product_Variation::is_type方法代码示例

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


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

示例1: 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

示例2: get_attributes

 /**
  * Get the attributes for a product or product variation.
  *
  * @param WC_Product|WC_Product_Variation $product Product instance.
  * @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);
             if (!$attribute) {
                 continue;
             }
             // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
             if (0 === strpos($attribute_name, 'attribute_pa_')) {
                 $option_term = get_term_by('slug', $attribute, $name);
                 $attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $option_term && !is_wp_error($option_term) ? $option_term->name : $attribute);
             } else {
                 $attributes[] = array('id' => 0, 'name' => $name, 'option' => $attribute);
             }
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             if ($attribute['is_taxonomy']) {
                 $attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($attribute['name']), 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
             } else {
                 $attributes[] = array('id' => 0, 'name' => $attribute['name'], 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
             }
         }
     }
     return $attributes;
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:35,代码来源:class-wc-rest-products-controller.php

示例3: 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' => ucwords(str_replace('attribute_', '', str_replace('pa_', '', $attribute_name))), 'option' => $attribute);
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             $attributes[] = array('name' => ucwords(str_replace('pa_', '', $attribute['name'])), 'position' => $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
         }
     }
     return $attributes;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:23,代码来源:class-wc-api-products.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_Variation::is_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。