本文整理汇总了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);
}
示例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);
}