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


PHP WC_Coupon::enable_free_shipping方法代码示例

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


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

示例1: prepare_item_for_response

 /**
  * Prepare a single coupon output for response.
  *
  * @param WP_Post $post Post object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response $data
  */
 public function prepare_item_for_response($post, $request)
 {
     global $wpdb;
     // Get the coupon code.
     $code = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE id = %s AND post_type = 'shop_coupon' AND post_status = 'publish'", $post->ID));
     $coupon = new WC_Coupon($code);
     $data = array('id' => $coupon->id, 'code' => $coupon->code, 'date_created' => wc_rest_prepare_date_response($post->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($post->post_modified_gmt), 'discount_type' => $coupon->type, 'description' => $post->post_excerpt, 'amount' => wc_format_decimal($coupon->coupon_amount, 2), 'expiry_date' => !empty($coupon->expiry_date) ? wc_rest_prepare_date_response($coupon->expiry_date) : null, 'usage_count' => (int) $coupon->usage_count, 'individual_use' => 'yes' === $coupon->individual_use, 'product_ids' => array_map('absint', (array) $coupon->product_ids), 'exclude_product_ids' => array_map('absint', (array) $coupon->exclude_product_ids), 'usage_limit' => !empty($coupon->usage_limit) ? $coupon->usage_limit : null, 'usage_limit_per_user' => !empty($coupon->usage_limit_per_user) ? $coupon->usage_limit_per_user : null, 'limit_usage_to_x_items' => (int) $coupon->limit_usage_to_x_items, 'free_shipping' => $coupon->enable_free_shipping(), 'product_categories' => array_map('absint', (array) $coupon->product_categories), 'excluded_product_categories' => array_map('absint', (array) $coupon->exclude_product_categories), 'exclude_sale_items' => $coupon->exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->minimum_amount, 2), 'maximum_amount' => wc_format_decimal($coupon->maximum_amount, 2), 'email_restrictions' => $coupon->customer_email, 'used_by' => $coupon->get_used_by());
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($post));
     /**
      * Filter the data for a response.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
      * prepared for the response.
      *
      * @param WP_REST_Response   $response   The response object.
      * @param WP_Post            $post       Post object.
      * @param WP_REST_Request    $request    Request object.
      */
     return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request);
 }
开发者ID:unfulvio,项目名称:woocommerce,代码行数:32,代码来源:class-wc-rest-coupons-controller.php

示例2: get_coupon

 /**
  * Get the coupon for the given ID
  *
  * @since 2.1
  * @param int $id the coupon ID
  * @param string $fields fields to include in response
  * @return array|WP_Error
  */
 public function get_coupon($id, $fields = null)
 {
     global $wpdb;
     $id = $this->validate_request($id, 'shop_coupon', 'read');
     if (is_wp_error($id)) {
         return $id;
     }
     // get the coupon code
     $code = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE id = %s AND post_type = 'shop_coupon' AND post_status = 'publish'", $id));
     if (is_null($code)) {
         return new WP_Error('woocommerce_api_invalid_coupon_id', __('Invalid coupon ID', 'woocommerce'), array('status' => 404));
     }
     $coupon = new WC_Coupon($code);
     $coupon_post = get_post($coupon->id);
     $coupon_data = array('id' => $coupon->id, 'code' => $coupon->code, 'type' => $coupon->type, 'created_at' => $this->server->format_datetime($coupon_post->post_date_gmt), 'updated_at' => $this->server->format_datetime($coupon_post->post_modified_gmt), 'amount' => wc_format_decimal($coupon->amount, 2), 'individual_use' => 'yes' === $coupon->individual_use, 'product_ids' => array_map('absint', (array) $coupon->product_ids), 'exclude_product_ids' => array_map('absint', (array) $coupon->exclude_product_ids), 'usage_limit' => !empty($coupon->usage_limit) ? $coupon->usage_limit : null, 'usage_limit_per_user' => !empty($coupon->usage_limit_per_user) ? $coupon->usage_limit_per_user : null, 'limit_usage_to_x_items' => (int) $coupon->limit_usage_to_x_items, 'usage_count' => (int) $coupon->usage_count, 'expiry_date' => $this->server->format_datetime($coupon->expiry_date), 'apply_before_tax' => $coupon->apply_before_tax(), 'enable_free_shipping' => $coupon->enable_free_shipping(), 'product_category_ids' => array_map('absint', (array) $coupon->product_categories), 'exclude_product_category_ids' => array_map('absint', (array) $coupon->exclude_product_categories), 'exclude_sale_items' => $coupon->exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->minimum_amount, 2), 'customer_emails' => $coupon->customer_email);
     return array('coupon' => apply_filters('woocommerce_api_coupon_response', $coupon_data, $coupon, $fields, $this->server));
 }
开发者ID:uwitec,项目名称:findgreatmaster,代码行数:25,代码来源:class-wc-api-coupons.php

示例3: foreach

 function is_available($package)
 {
     global $woocommerce;
     if ($this->enabled == "no") {
         return false;
     }
     $ship_to_countries = '';
     if ($this->availability == 'specific') {
         $ship_to_countries = $this->countries;
     } else {
         if (get_option('woocommerce_allowed_countries') == 'specific') {
             $ship_to_countries = get_option('woocommerce_specific_allowed_countries');
         }
     }
     if (is_array($ship_to_countries)) {
         if (!in_array($package['destination']['country'], $ship_to_countries)) {
             return false;
         }
     }
     // Enabled logic
     $is_available = true;
     if ($this->requires_coupon == "yes") {
         if ($woocommerce->cart->applied_coupons) {
             foreach ($woocommerce->cart->applied_coupons as $code) {
                 $coupon = new WC_Coupon($code);
                 if ($coupon->enable_free_shipping()) {
                     return true;
                 }
             }
         }
         // No coupon found, as it stands, free shipping is disabled
         $is_available = false;
     }
     if (isset($woocommerce->cart->cart_contents_total) && !empty($this->min_amount)) {
         if ($woocommerce->cart->prices_include_tax) {
             $total = $woocommerce->cart->tax_total + $woocommerce->cart->cart_contents_total;
         } else {
             $total = $woocommerce->cart->cart_contents_total;
         }
         if ($this->min_amount > $total) {
             $is_available = false;
         } else {
             $is_available = true;
         }
     }
     return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available);
 }
开发者ID:eddiewilson,项目名称:new-ke,代码行数:47,代码来源:class-wc-free-shipping.php

示例4: foreach

 /**
  * is_available function.
  *
  * @access public
  * @param mixed $package
  * @return bool
  */
 function is_available($package)
 {
     global $woocommerce;
     if ($this->enabled == "no") {
         return false;
     }
     $ship_to_countries = '';
     if ($this->availability == 'specific') {
         $ship_to_countries = $this->countries;
     } else {
         if (get_option('woocommerce_allowed_countries') == 'specific') {
             $ship_to_countries = get_option('woocommerce_specific_allowed_countries');
         }
     }
     if (is_array($ship_to_countries)) {
         if (!in_array($package['destination']['country'], $ship_to_countries)) {
             return false;
         }
     }
     // Enabled logic
     $is_available = false;
     $has_coupon = false;
     $has_met_min_amount = false;
     if (in_array($this->requires, array('coupon', 'either', 'both'))) {
         if ($woocommerce->cart->applied_coupons) {
             foreach ($woocommerce->cart->applied_coupons as $code) {
                 $coupon = new WC_Coupon($code);
                 if ($coupon->is_valid() && $coupon->enable_free_shipping()) {
                     $has_coupon = true;
                 }
             }
         }
     }
     if (in_array($this->requires, array('min_amount', 'either', 'both')) && isset($woocommerce->cart->cart_contents_total)) {
         if ($woocommerce->cart->prices_include_tax) {
             $total = $woocommerce->cart->cart_contents_total + array_sum($woocommerce->cart->taxes);
         } else {
             $total = $woocommerce->cart->cart_contents_total;
         }
         if ($total >= $this->min_amount) {
             $has_met_min_amount = true;
         }
     }
     switch ($this->requires) {
         case 'min_amount':
             if ($has_met_min_amount) {
                 $is_available = true;
             }
             break;
         case 'coupon':
             if ($has_coupon) {
                 $is_available = true;
             }
             break;
         case 'both':
             if ($has_met_min_amount && $has_coupon) {
                 $is_available = true;
             }
             break;
         case 'either':
             if ($has_met_min_amount || $has_coupon) {
                 $is_available = true;
             }
             break;
         default:
             $is_available = true;
             break;
     }
     return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available);
 }
开发者ID:shahadat014,项目名称:geleyi,代码行数:77,代码来源:class-wc-shipping-free-shipping.php

示例5: 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

示例6: foreach

 function is_available()
 {
     global $woocommerce;
     if ($this->enabled == "no") {
         return false;
     }
     $ship_to_countries = '';
     if ($this->availability == 'specific') {
         $ship_to_countries = $this->countries;
     } else {
         if (get_option('woocommerce_allowed_countries') == 'specific') {
             $ship_to_countries = get_option('woocommerce_specific_allowed_countries');
         }
     }
     if (is_array($ship_to_countries)) {
         if (!in_array($woocommerce->customer->get_shipping_country(), $ship_to_countries)) {
             return false;
         }
     }
     if ($this->requires_coupon == "yes") {
         if ($woocommerce->cart->applied_coupons) {
             foreach ($woocommerce->cart->applied_coupons as $code) {
                 $coupon = new WC_Coupon($code);
                 if ($coupon->enable_free_shipping()) {
                     return true;
                 }
             }
         }
         return false;
     }
     if (isset($woocommerce->cart->cart_contents_total)) {
         if ($woocommerce->cart->prices_include_tax) {
             $total = $woocommerce->cart->tax_total + $woocommerce->cart->cart_contents_total;
         } else {
             $total = $woocommerce->cart->cart_contents_total;
         }
         if (isset($this->min_amount) && $this->min_amount && $this->min_amount > $total) {
             return false;
         }
     }
     return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', true);
 }
开发者ID:bidhanbaral,项目名称:fotodep_store,代码行数:42,代码来源:class-wc-free-shipping.php


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