/**
  * 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;
 }
 /**
  * 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);
 }
 * @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 
Example #4
0
 /**
  * @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;
 }
 /**
  * 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;
 }