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


PHP WC_Product::__get方法代码示例

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


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

示例1: __get

 /**
  * Get method returns variation meta data if set, otherwise in most cases the data from the parent.
  *
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (in_array($key, array_keys($this->variation_level_meta_data))) {
         $value = get_post_meta($this->variation_id, '_' . $key, true);
         if ('' === $value) {
             $value = $this->variation_level_meta_data[$key];
         }
     } elseif (in_array($key, array_keys($this->variation_inherited_meta_data))) {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : get_post_meta($this->id, '_' . $key, true);
         // Handle meta data keys which can be empty at variation level to cause inheritance
         if ('' === $value && in_array($key, array('sku', 'weight', 'length', 'width', 'height'))) {
             $value = get_post_meta($this->id, '_' . $key, true);
         }
         if ('' === $value) {
             $value = $this->variation_inherited_meta_data[$key];
         }
     } elseif ('variation_data' === $key) {
         return $this->variation_data = wc_get_product_variation_attributes($this->variation_id);
     } elseif ('variation_has_stock' === $key) {
         return $this->managing_stock();
     } else {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : parent::__get($key);
     }
     return $value;
 }
开发者ID:noman1059,项目名称:woocommerce,代码行数:31,代码来源:class-wc-product-variation.php

示例2: __get

 /**
  * Get method returns variation meta data if set, otherwise in most cases the data from the parent.
  *
  * @access public
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (in_array($key, array_keys($this->variation_level_meta_data))) {
         $value = get_post_meta($this->variation_id, '_' . $key, true);
         if ('' === $value) {
             $value = $this->variation_level_meta_data[$key];
         }
     } elseif (in_array($key, array_keys($this->variation_inherited_meta_data))) {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : get_post_meta($this->id, '_' . $key, true);
         // Handle meta data keys which can be empty at variation level to cause inheritance
         if ('' === $value && in_array($key, array('sku', 'weight', 'length', 'width', 'height'))) {
             $value = get_post_meta($this->id, '_' . $key, true);
         }
         if ('' === $value) {
             $value = $this->variation_inherited_meta_data[$key];
         }
     } elseif ('variation_data' === $key) {
         $all_meta = get_post_meta($this->variation_id);
         // The variation data array
         $this->variation_data = array();
         // Get the variation attributes from meta
         foreach ($all_meta as $name => $value) {
             if (!strstr($name, 'attribute_')) {
                 continue;
             }
             $this->variation_data[$name] = sanitize_title($value[0]);
         }
         return $this->variation_data;
     } elseif ('variation_has_stock' === $key) {
         return $this->managing_stock();
     } else {
         $value = parent::__get($key);
     }
     return $value;
 }
开发者ID:donpapa26,项目名称:bakancslistad,代码行数:42,代码来源:class-wc-product-variation.php

示例3: __get

 /**
  * Get method returns variation meta data if set, otherwise in most cases the data from the parent.
  *
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (in_array($key, array_keys($this->variation_level_meta_data))) {
         $value = get_post_meta($this->variation_id, '_' . $key, true);
         if ('' === $value) {
             $value = $this->variation_level_meta_data[$key];
         }
     } elseif (in_array($key, array_keys($this->variation_inherited_meta_data))) {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : get_post_meta($this->id, '_' . $key, true);
         // Handle meta data keys which can be empty at variation level to cause inheritance
         if ('' === $value && in_array($key, array('sku', 'weight', 'length', 'width', 'height'))) {
             $value = get_post_meta($this->id, '_' . $key, true);
         }
         if ('' === $value) {
             $value = $this->variation_inherited_meta_data[$key];
         }
     } elseif ('variation_data' === $key) {
         $all_meta = get_post_meta($this->variation_id);
         // The variation data array
         $this->variation_data = array();
         // Get the variation attributes from meta
         foreach ($all_meta as $name => $value) {
             if (0 !== strpos($name, 'attribute_')) {
                 continue;
             }
             /**
              * Pre 2.4 handling where 'slugs' were saved instead of the full text attribute.
              * Attempt to get full version of the text attribute from the parent.
              */
             if (sanitize_title($value[0]) === $value[0] && version_compare(get_post_meta($this->id, '_product_version', true), '2.4.0', '<')) {
                 $attributes = $this->parent->get_attributes();
                 foreach ($attributes as $attribute) {
                     if ($name !== 'attribute_' . sanitize_title($attribute['name'])) {
                         continue;
                     }
                     $text_attributes = wc_get_text_attributes($attribute['value']);
                     foreach ($text_attributes as $text_attribute) {
                         if (sanitize_title($text_attribute) === $value[0]) {
                             $value[0] = $text_attribute;
                         }
                     }
                 }
             }
             $this->variation_data[$name] = $value[0];
         }
         return $this->variation_data;
     } elseif ('variation_has_stock' === $key) {
         return $this->managing_stock();
     } else {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : parent::__get($key);
     }
     return $value;
 }
开发者ID:johnmooredesign,项目名称:woocommerce,代码行数:59,代码来源:class-wc-product-variation.php


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