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


PHP WC_Product::get_parent方法代码示例

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


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

示例1: smart_coupons_is_valid_for_product

 /**
  * function to validate smart coupon for product
  *
  * @param bool $valid
  * @param WC_Product|null $product
  * @param WC_Coupon|null $coupon
  * @param array|null $values
  * @return bool $valid
  */
 public function smart_coupons_is_valid_for_product($valid, $product = null, $coupon = null, $values = null)
 {
     if (empty($product) || empty($coupon)) {
         return $valid;
     }
     if ($coupon->discount_type == 'smart_coupon') {
         $product_cats = wp_get_post_terms($product->id, 'product_cat', array("fields" => "ids"));
         // Specific products get the discount
         if (sizeof($coupon->product_ids) > 0) {
             if (in_array($product->id, $coupon->product_ids) || isset($product->variation_id) && in_array($product->variation_id, $coupon->product_ids) || in_array($product->get_parent(), $coupon->product_ids)) {
                 $valid = true;
             }
             // Category discounts
         } elseif (sizeof($coupon->product_categories) > 0) {
             if (sizeof(array_intersect($product_cats, $coupon->product_categories)) > 0) {
                 $valid = true;
             }
         } else {
             // No product ids - all items discounted
             $valid = true;
         }
         // Specific product ID's excluded from the discount
         if (sizeof($coupon->exclude_product_ids) > 0) {
             if (in_array($product->id, $coupon->exclude_product_ids) || isset($product->variation_id) && in_array($product->variation_id, $coupon->exclude_product_ids) || in_array($product->get_parent(), $coupon->exclude_product_ids)) {
                 $valid = false;
             }
         }
         // Specific categories excluded from the discount
         if (sizeof($coupon->exclude_product_categories) > 0) {
             if (sizeof(array_intersect($product_cats, $coupon->exclude_product_categories)) > 0) {
                 $valid = false;
             }
         }
         // Sale Items excluded from discount
         if ($coupon->exclude_sale_items == 'yes') {
             $product_ids_on_sale = wc_get_product_ids_on_sale();
             if (in_array($product->id, $product_ids_on_sale, true) || isset($product->variation_id) && in_array($product->variation_id, $product_ids_on_sale, true) || in_array($product->get_parent(), $product_ids_on_sale, true)) {
                 $valid = false;
             }
         }
     }
     return $valid;
 }
开发者ID:NerdyDillinger,项目名称:ovrride,代码行数:52,代码来源:woocommerce-smart-coupons.php

示例2: is_valid_for_product

 /**
  * Check if a coupon is valid for a product
  * 
  * @param  WC_Product  $product
  * @return boolean
  */
 public function is_valid_for_product($product)
 {
     if ($this->type != 'fixed_product' && $this->type != 'percent_product') {
         return false;
     }
     $valid = false;
     $product_cats = wp_get_post_terms($product->id, 'product_cat', array("fields" => "ids"));
     // Specific products get the discount
     if (sizeof($this->product_ids) > 0) {
         if (in_array($product->id, $this->product_ids) || isset($product->variation_id) && in_array($product->variation_id, $this->product_ids) || in_array($product->get_parent(), $this->product_ids)) {
             $valid = true;
         }
         // Category discounts
     } elseif (sizeof($this->product_categories) > 0) {
         if (sizeof(array_intersect($product_cats, $this->product_categories)) > 0) {
             $valid = true;
         }
     } else {
         // No product ids - all items discounted
         $valid = true;
     }
     // Specific product ID's excluded from the discount
     if (sizeof($this->exclude_product_ids) > 0) {
         if (in_array($product->id, $this->exclude_product_ids) || isset($product->variation_id) && in_array($product->variation_id, $this->exclude_product_ids) || in_array($product->get_parent(), $this->exclude_product_ids)) {
             $valid = false;
         }
     }
     // Specific categories excluded from the discount
     if (sizeof($this->exclude_product_categories) > 0) {
         if (sizeof(array_intersect($product_cats, $this->exclude_product_categories)) > 0) {
             $valid = false;
         }
     }
     // Sale Items excluded from discount
     if ($this->exclude_sale_items == 'yes') {
         $product_ids_on_sale = wc_get_product_ids_on_sale();
         if (in_array($product->id, $product_ids_on_sale, true) || isset($product->variation_id) && in_array($product->variation_id, $product_ids_on_sale, true) || in_array($product->get_parent(), $product_ids_on_sale, true)) {
             $valid = false;
         }
     }
     return apply_filters('woocommerce_coupon_is_valid_for_product', $valid, $product, $this);
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:48,代码来源:class-wc-coupon.php

示例3:

 * @version   2.3.8
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $WOO_Product_Stock_Alert;
do_action('woocommerce_email_header', $email_heading);
?>

<p><?php 
printf(__("Hi there. You have subscribed a product. Your subscribed product is available now. Product details are shown below for your reference:", $WOO_Product_Stock_Alert->text_domain));
$product_obj = wc_get_product($product_id);
if ($product_obj->is_type('variation')) {
    $wp_obj = new WC_Product($product_id);
    $parent_id = $wp_obj->get_parent();
    $parent_obj = new WC_Product($parent_id);
    $product_link = $parent_obj->get_permalink();
    $product_name = $wp_obj->post->post_title;
    $product_price = $product_obj->get_price_html();
} else {
    $product_link = $product_obj->get_permalink();
    $product_name = $product_obj->get_formatted_name();
    $product_price = $product_obj->get_price_html();
}
?>
<h3>Product Details</h3>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
	<thead>
		<tr>
			<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php 
开发者ID:JaneJieYing,项目名称:HiFridays,代码行数:31,代码来源:stock_alert_email.php

示例4: replace_expiration_vars

 /**
  * @param string $content
  * @param License $license
  *
  * @return string
  */
 private function replace_expiration_vars($content, $license)
 {
     // get user
     $user = get_user_by('id', $license->get_user_id());
     // get first name
     $fname = 'there';
     if (!empty($user) && !empty($user->first_name)) {
         $fname = $user->first_name;
     }
     // get WooCommerce product object
     $wc_product = new \WC_Product($license->get_product_id());
     // get parent product if the product has one
     if (0 != $wc_product->get_parent()) {
         $wc_product = new \WC_Product($wc_product->get_parent());
     }
     $content = str_ireplace(':fname:', $fname, $content);
     $content = str_ireplace(':product:', $wc_product->get_title(), $content);
     $content = str_ireplace(':license-key:', $license->get_key(), $content);
     $content = str_ireplace(':license-expiration-date:', $license->get_date_expires() ? $license->get_date_expires()->format('M d Y') : '', $content);
     $content = str_ireplace(':renewal-link:', $license->get_renewal_url(), $content);
     return $content;
 }
开发者ID:yehudah,项目名称:license-wp,代码行数:28,代码来源:Manager.php

示例5: get_product

 /**
  * Gets the identified product. Compatible with WC 2.0 and backwards
  * compatible with previous versions
  *
  * @param int $product_id the product identifier
  * @param array $args optional array of arguments
  *
  * @return WC_Product the product
  */
 public function get_product($product_id, $args = array())
 {
     $product = null;
     if (version_compare(WOOCOMMERCE_VERSION, "2.0.0") >= 0) {
         // WC 2.0
         $product = get_product($product_id, $args);
     } else {
         // old style, get the product or product variation object
         if (isset($args['parent_id']) && $args['parent_id']) {
             $product = new WC_Product_Variation($product_id, $args['parent_id']);
         } else {
             // get the regular product, but if it has a parent, return the product variation object
             $product = new WC_Product($product_id);
             if ($product->get_parent()) {
                 $product = new WC_Product_Variation($product->id, $product->get_parent());
             }
         }
     }
     return $product;
 }
开发者ID:shahadat014,项目名称:geleyi,代码行数:29,代码来源:woocommerce-tab-manager.php


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