當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WC_Coupon::is_valid_for_cart方法代碼示例

本文整理匯總了PHP中WC_Coupon::is_valid_for_cart方法的典型用法代碼示例。如果您正苦於以下問題:PHP WC_Coupon::is_valid_for_cart方法的具體用法?PHP WC_Coupon::is_valid_for_cart怎麽用?PHP WC_Coupon::is_valid_for_cart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WC_Coupon的用法示例。


在下文中一共展示了WC_Coupon::is_valid_for_cart方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_discounted_price

 /**
  * Function to apply discounts to a product and get the discounted price (before tax is applied).
  *
  * @access public
  * @param mixed $values
  * @param mixed $price
  * @param bool $add_totals (default: false)
  * @return float price
  */
 public function get_discounted_price($values, $price, $add_totals = false)
 {
     if (!$price) {
         return $price;
     }
     if (!empty($this->applied_coupons)) {
         foreach ($this->applied_coupons as $code) {
             $coupon = new WC_Coupon($code);
             if ($coupon->apply_before_tax() && $coupon->is_valid()) {
                 if ($coupon->is_valid_for_product($values['data']) || $coupon->is_valid_for_cart()) {
                     $discount_amount = $coupon->get_discount_amount($price, $values, $single = true);
                     $price = max($price - $discount_amount, 0);
                     if ($add_totals) {
                         $this->discount_cart += $discount_amount * $values['quantity'];
                         $this->increase_coupon_discount_amount($code, $discount_amount * $values['quantity']);
                         $this->increase_coupon_applied_count($code, $values['quantity']);
                     }
                 }
             }
         }
     }
     return apply_filters('woocommerce_get_discounted_price', $price, $values, $this);
 }
開發者ID:Joaquinsemp,項目名稱:patriestausado,代碼行數:32,代碼來源:class-wc-cart.php

示例2: foreach

 /**
  * Does the coupon have a value? (autocoupon should not be applied if it has no value)
  * @param  WC_Coupon $coupon The coupon data
  * @return bool True if it has a value (discount, free shipping, whatever) otherwise false)
  **/
 function coupon_has_a_value($coupon)
 {
     $has_a_value = false;
     if ($coupon->enable_free_shipping()) {
         $has_a_value = true;
     } else {
         //Test whether discount > 0
         //See WooCommerce: class-wc-cart.php function get_discounted_price
         global $woocommerce;
         foreach ($woocommerce->cart->get_cart() as $cart_item) {
             if ($coupon->is_valid_for_cart() || $coupon->is_valid_for_product($cart_item['data'], $cart_item)) {
                 if ($coupon->get_discount_amount($cart_item['data']->price, $cart_item) > 0) {
                     $has_a_value = true;
                     break;
                 }
             }
         }
     }
     return apply_filters('wjecf_coupon_has_a_value', $has_a_value, $coupon);
 }
開發者ID:JaneJieYing,項目名稱:kiddoonline_dvlpment,代碼行數:25,代碼來源:wjecf-autocoupon.php


注:本文中的WC_Coupon::is_valid_for_cart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。