• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WC_Coupon类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: apply_coupon

 /**
  * AJAX apply coupon on checkout page
  */
 public function apply_coupon()
 {
     check_ajax_referer('apply-coupon', 'security');
     if (!empty($_POST['coupon_code'])) {
         WC()->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
     } else {
         wc_add_notice(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER), 'error');
     }
     wc_print_notices();
     die;
 }
开发者ID:chhavinav,项目名称:fr.ilovejuice,代码行数:14,代码来源:class-wc-ajax.php


示例2: apply_subscription_discount_before_tax

 /**
  * Apply sign up fee or recurring fee discount before tax is calculated
  *
  *
  * @since 1.2
  */
 public static function apply_subscription_discount_before_tax($original_price, $product, $cart)
 {
     global $woocommerce;
     if (!WC_Subscriptions_Product::is_subscription($product['product_id'])) {
         return $original_price;
     }
     $price = $original_price;
     if (!empty($cart->applied_coupons)) {
         foreach ($cart->applied_coupons as $code) {
             $coupon = new WC_Coupon($code);
             if ($coupon->apply_before_tax() && $coupon->is_valid()) {
                 // Sign up fee discount
                 if ('sign_up_fee' == WC_Subscriptions_Cart::get_recalculation_type() && 'sign_up_fee' == $coupon->type || 'base_recurring_fee' == WC_Subscriptions_Cart::get_recalculation_type() && 'recurring_fee' == $coupon->type || 0 == WC_Subscriptions_Cart::get_cart_subscription_sign_up_fee() && 'recurring_fee' == $coupon->type) {
                     if ($original_price < $coupon->amount) {
                         $discount_amount = $original_price;
                     } else {
                         $discount_amount = $coupon->amount;
                     }
                     $price = $original_price - $coupon->amount;
                     if ($price < 0) {
                         $price = 0;
                     }
                     // add to discount totals
                     $woocommerce->cart->discount_cart = $woocommerce->cart->discount_cart + $discount_amount * $product['quantity'];
                 }
             }
         }
     }
     return $price;
 }
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:36,代码来源:class-wc-subscriptions-coupon.php


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


示例4: wp_init

 /**
  * Automatically apply coupons.
  * 
  * Also removes auto-apply coupons (although that should happen
  * automatically, it seems we're on the safer side doing that as well
  * here).
  */
 public static function wp_init()
 {
     global $wpdb, $woocommerce;
     if (isset($woocommerce) && isset($woocommerce->cart) && $woocommerce->cart->coupons_enabled()) {
         $coupons = $wpdb->get_results("SELECT DISTINCT ID, post_title FROM {$wpdb->posts} LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE {$wpdb->posts}.post_status = 'publish' AND {$wpdb->postmeta}.meta_key = '_vd_auto'");
         if ($coupons && count($coupons) > 0) {
             foreach ($coupons as $coupon) {
                 $coupon_code = $coupon->post_title;
                 $coupon = new WC_Coupon($coupon_code);
                 if ($coupon->id) {
                     if ($coupon->is_valid()) {
                         if (!$woocommerce->cart->has_discount($coupon_code)) {
                             $woocommerce->cart->add_discount($coupon_code);
                             $msg = '';
                             $message = get_post_meta($coupon->id, '_vd_auto_message_display', true);
                             $show_description = get_post_meta($coupon->id, '_vd_auto_description_display', true) == 'yes';
                             $show_info = get_post_meta($coupon->id, '_vd_auto_info_display', true) == 'yes';
                             if (!empty($message)) {
                                 $msg .= sprintf('<div class="coupon display message %s">', wp_strip_all_tags($coupon->code));
                                 $msg .= stripslashes(wp_filter_kses($message));
                                 $msg .= '</div>';
                             }
                             if ($show_description) {
                                 if ($post = get_post($coupon->id)) {
                                     if (!empty($post->post_excerpt)) {
                                         $msg .= sprintf('<div class="coupon display description %s">', wp_strip_all_tags($coupon->code));
                                         $msg .= stripslashes(wp_filter_kses($post->post_excerpt));
                                         $msg .= '</div>';
                                     }
                                 }
                             }
                             if ($show_info) {
                                 $msg .= sprintf('<div class="coupon display volume-discount %s">', wp_strip_all_tags($coupon->code));
                                 $msg .= WooCommerce_Volume_Discount_Coupons_Shortcodes::get_volume_discount_info($coupon);
                                 $msg .= '</div>';
                             }
                             if (!empty($msg)) {
                                 $woocommerce->add_message($msg);
                             }
                         }
                     } else {
                         if ($woocommerce->cart->has_discount($coupon_code)) {
                             if (!empty($woocommerce->cart->applied_coupons)) {
                                 foreach ($woocommerce->cart->applied_coupons as $index => $code) {
                                     if ($coupon_code == $code) {
                                         unset($woocommerce->cart->applied_coupons[$index]);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:tleonard2,项目名称:durablegbFeb,代码行数:63,代码来源:class-woocommerce-volume-discount-coupons-coupon.php


示例5: 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)
 {
     try {
         $id = $this->validate_request($id, 'shop_coupon', 'read');
         if (is_wp_error($id)) {
             return $id;
         }
         $coupon = new WC_Coupon($id);
         if (0 === $coupon->get_id()) {
             throw new WC_API_Exception('woocommerce_api_invalid_coupon_id', __('Invalid coupon ID', 'woocommerce'), 404);
         }
         $coupon_data = array('id' => $coupon->get_id(), 'code' => $coupon->get_code(), 'type' => $coupon->get_discount_type(), 'created_at' => $this->server->format_datetime($coupon->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($coupon->get_date_modified(), false, true), 'amount' => wc_format_decimal($coupon->get_amount(), 2), 'individual_use' => $coupon->get_individual_use(), 'product_ids' => array_map('absint', (array) $coupon->get_product_ids()), 'exclude_product_ids' => array_map('absint', (array) $coupon->get_excluded_product_ids()), 'usage_limit' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : null, 'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null, 'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(), 'usage_count' => (int) $coupon->get_usage_count(), 'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime($coupon->get_date_expires()) : null, 'enable_free_shipping' => $coupon->get_free_shipping(), 'product_category_ids' => array_map('absint', (array) $coupon->get_product_categories()), 'exclude_product_category_ids' => array_map('absint', (array) $coupon->get_excluded_product_categories()), 'exclude_sale_items' => $coupon->get_exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->get_minimum_amount(), 2), 'maximum_amount' => wc_format_decimal($coupon->get_maximum_amount(), 2), 'customer_emails' => $coupon->get_email_restrictions(), 'description' => $coupon->get_description());
         return array('coupon' => apply_filters('woocommerce_api_coupon_response', $coupon_data, $coupon, $fields, $this->server));
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:25,代码来源:class-wc-api-coupons.php


示例6: output

 /**
  * Output the cart shortcode.
  *
  * @access public
  * @param array $atts
  * @return void
  */
 public static function output($atts)
 {
     global $woocommerce;
     if (!defined('WOOCOMMERCE_CART')) {
         define('WOOCOMMERCE_CART', true);
     }
     // Add Discount
     if (!empty($_POST['apply_coupon'])) {
         if (!empty($_POST['coupon_code'])) {
             $woocommerce->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
         } else {
             $woocommerce->add_error(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER));
         }
         // Remove Coupon Codes
     } elseif (isset($_GET['remove_discounts'])) {
         $woocommerce->cart->remove_coupons($_GET['remove_discounts']);
         // Update Shipping
     } elseif (!empty($_POST['calc_shipping']) && $woocommerce->verify_nonce('cart')) {
         $validation = $woocommerce->validation();
         $woocommerce->shipping->reset_shipping();
         $woocommerce->customer->calculated_shipping(true);
         $country = woocommerce_clean($_POST['calc_shipping_country']);
         $state = woocommerce_clean($_POST['calc_shipping_state']);
         $postcode = apply_filters('woocommerce_shipping_calculator_enable_postcode', true) ? woocommerce_clean($_POST['calc_shipping_postcode']) : '';
         $city = apply_filters('woocommerce_shipping_calculator_enable_city', false) ? woocommerce_clean($_POST['calc_shipping_city']) : '';
         if ($postcode && !$validation->is_postcode($postcode, $country)) {
             $woocommerce->add_error(__('Please enter a valid postcode/ZIP.', 'woocommerce'));
             $postcode = '';
         } elseif ($postcode) {
             $postcode = $validation->format_postcode($postcode, $country);
         }
         if ($country) {
             // Update customer location
             $woocommerce->customer->set_location($country, $state, $postcode, $city);
             $woocommerce->customer->set_shipping_location($country, $state, $postcode, $city);
             $woocommerce->add_message(__('Shipping costs updated.', 'woocommerce'));
         } else {
             $woocommerce->customer->set_to_base();
             $woocommerce->customer->set_shipping_to_base();
             $woocommerce->add_message(__('Shipping costs updated.', 'woocommerce'));
         }
         do_action('woocommerce_calculated_shipping');
     }
     // Check cart items are valid
     do_action('woocommerce_check_cart_items');
     // Calc totals
     $woocommerce->cart->calculate_totals();
     if (sizeof($woocommerce->cart->get_cart()) == 0) {
         //woocommerce_get_template( 'cart/cart-empty.php' );
         woocommerce_get_template('checkout/form-checkout.php');
     } else {
         //woocommerce_get_template( 'cart/cart.php' );
         woocommerce_get_template('checkout/form-checkout.php');
     }
 }
开发者ID:par-orillonsoft,项目名称:elearning-wordpress,代码行数:62,代码来源:class-wc-shortcode-cart.php


示例7: _is_valid

 /**
  * Evaluate common validity based on op and coupon codes.
  * 
  * @param array $atts
  * @return boolean
  */
 private static function _is_valid($atts)
 {
     $options = shortcode_atts(array('coupon' => null, 'code' => null, 'op' => 'and'), $atts);
     $code = null;
     if (!empty($options['code'])) {
         $code = $options['code'];
     } else {
         if (!empty($options['coupon'])) {
             $code = $options['coupon'];
         }
     }
     if ($code === null) {
         return '';
     }
     $codes = array_map('trim', explode(',', $code));
     $validities = array();
     foreach ($codes as $code) {
         $coupon = new WC_Coupon($code);
         if ($coupon->id) {
             $validities[] = $coupon->is_valid();
         }
     }
     if (count($validities) > 0) {
         $valid = $options['op'] != 'or';
         foreach ($validities as $validity) {
             if ($options['op'] == 'or') {
                 $valid = $valid || $validity;
                 if ($valid) {
                     break;
                 }
             } else {
                 $valid = $valid && $validity;
                 if (!$valid) {
                     break;
                 }
             }
         }
     } else {
         $valid = false;
     }
 }
开发者ID:tleonard2,项目名称:durablegbFeb,代码行数:47,代码来源:class-woocommerce-volume-discount-coupons-shortcodes.php


示例8: woocommerce_ajax_apply_coupon

/**
 * AJAX apply coupon on checkout page
 *
 * @access public
 * @return void
 */
function woocommerce_ajax_apply_coupon()
{
    global $woocommerce;
    check_ajax_referer('apply-coupon', 'security');
    if (!empty($_POST['coupon_code'])) {
        $woocommerce->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
    } else {
        $woocommerce->add_error(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER));
    }
    $woocommerce->show_messages();
    die;
}
开发者ID:rongandat,项目名称:sallumeh,代码行数:18,代码来源:woocommerce-ajax.php


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


示例10: apply_subscription_discount

 /**
  * Apply sign up fee or recurring fee discount
  *
  * @since 1.2
  */
 public static function apply_subscription_discount($original_price, $cart_item, $cart)
 {
     $product_id = $cart_item['data']->is_type(array('subscription_variation')) ? $cart_item['data']->variation_id : $cart_item['data']->id;
     if (!WC_Subscriptions_Product::is_subscription($product_id)) {
         return $original_price;
     }
     $price = $calculation_price = $original_price;
     $calculation_type = WC_Subscriptions_Cart::get_calculation_type();
     if (!empty($cart->applied_coupons)) {
         foreach ($cart->applied_coupons as $code) {
             $coupon = new WC_Coupon($code);
             if ($coupon->apply_before_tax() && $coupon->is_valid()) {
                 $apply_recurring_coupon = $apply_recurring_percent_coupon = $apply_initial_coupon = $apply_initial_percent_coupon = false;
                 // Apply recurring fee discounts to recurring total calculations
                 if ('recurring_total' == $calculation_type) {
                     $apply_recurring_coupon = 'recurring_fee' == $coupon->type ? true : false;
                     $apply_recurring_percent_coupon = 'recurring_percent' == $coupon->type ? true : false;
                 }
                 if ('none' == $calculation_type) {
                     // If all items have a free trial we don't need to apply recurring coupons to the initial total
                     if (!WC_Subscriptions_Cart::all_cart_items_have_free_trial()) {
                         if ('recurring_fee' == $coupon->type) {
                             $apply_initial_coupon = true;
                         }
                         if ('recurring_percent' == $coupon->type) {
                             $apply_initial_percent_coupon = true;
                         }
                     }
                     // Apply sign-up discounts to initial total
                     if (!empty($cart_item['data']->subscription_sign_up_fee)) {
                         if ('sign_up_fee' == $coupon->type) {
                             $apply_initial_coupon = true;
                         }
                         if ('sign_up_fee_percent' == $coupon->type) {
                             $apply_initial_percent_coupon = true;
                         }
                         $calculation_price = $cart_item['data']->subscription_sign_up_fee;
                     }
                 }
                 if ($apply_recurring_coupon || $apply_initial_coupon) {
                     $discount_amount = $calculation_price < $coupon->amount ? $calculation_price : $coupon->amount;
                     // Recurring coupons only apply when there is no free trial (carts can have a mix of free trial and non free trial items)
                     if ($apply_initial_coupon && 'recurring_fee' == $coupon->type && !empty($cart_item['data']->subscription_trial_length)) {
                         $discount_amount = 0;
                     }
                     $cart->discount_cart = $cart->discount_cart + $discount_amount * $cart_item['quantity'];
                     $cart = self::increase_coupon_discount_amount($cart, $coupon->code, $discount_amount * $cart_item['quantity']);
                     $price = $price - $discount_amount;
                 } elseif ($apply_recurring_percent_coupon) {
                     $discount_amount = round($calculation_price / 100 * $coupon->amount, WC()->cart->dp);
                     $cart->discount_cart = $cart->discount_cart + $discount_amount * $cart_item['quantity'];
                     $cart = self::increase_coupon_discount_amount($cart, $coupon->code, $discount_amount * $cart_item['quantity']);
                     $price = $price - $discount_amount;
                 } elseif ($apply_initial_percent_coupon) {
                     // Recurring coupons only apply when there is no free trial (carts can have a mix of free trial and non free trial items)
                     if ('recurring_percent' == $coupon->type && empty($cart_item['data']->subscription_trial_length)) {
                         $amount_to_discount = $cart_item['data']->subscription_price;
                     } else {
                         $amount_to_discount = 0;
                     }
                     // Sign up fee coupons only apply to sign up fees
                     if ('sign_up_fee_percent' == $coupon->type) {
                         $amount_to_discount = $cart_item['data']->subscription_sign_up_fee;
                     }
                     $discount_amount = round($amount_to_discount / 100 * $coupon->amount, WC()->cart->dp);
                     $cart->discount_cart = $cart->discount_cart + $discount_amount * $cart_item['quantity'];
                     $cart = self::increase_coupon_discount_amount($cart, $coupon->code, $discount_amount * $cart_item['quantity']);
                     $price = $price - $discount_amount;
                 }
             }
         }
         if ($price < 0) {
             $price = 0;
         }
     }
     return $price;
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:82,代码来源:class-wc-subscriptions-coupon.php


示例11: wc_cart_totals_coupon_html

/**
 * Get a coupon value.
 *
 * @access public
 * @param string $coupon
 */
function wc_cart_totals_coupon_html($coupon)
{
    if (is_string($coupon)) {
        $coupon = new WC_Coupon($coupon);
    }
    $value = array();
    if ($amount = WC()->cart->get_coupon_discount_amount($coupon->get_code(), WC()->cart->display_cart_ex_tax)) {
        $discount_html = '-' . wc_price($amount);
    } else {
        $discount_html = '';
    }
    $value[] = apply_filters('woocommerce_coupon_discount_amount_html', $discount_html, $coupon);
    if ($coupon->get_free_shipping()) {
        $value[] = __('Free shipping coupon', 'woocommerce');
    }
    // get rid of empty array elements
    $value = array_filter($value);
    $value = implode(', ', $value) . ' <a href="' . esc_url(add_query_arg('remove_coupon', urlencode($coupon->get_code()), defined('WOOCOMMERCE_CHECKOUT') ? wc_get_checkout_url() : wc_get_cart_url())) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr($coupon->get_code()) . '">' . __('[Remove]', 'woocommerce') . '</a>';
    echo apply_filters('woocommerce_cart_totals_coupon_html', $value, $coupon);
}
开发者ID:nishitlangaliya,项目名称:woocommerce,代码行数:26,代码来源:wc-cart-functions.php


示例12: apply_fake_coupon

 /**
  * Apply fake coupon to cart
  * 
  * @access public
  * @return void
  */
 public function apply_fake_coupon()
 {
     global $woocommerce;
     $the_coupon = new WC_Coupon(apply_filters('woocommerce_coupon_code', $this->opt['settings']['cart_discount_title']));
     if ($the_coupon->is_valid() && !$woocommerce->cart->has_discount($this->opt['settings']['cart_discount_title'])) {
         // Do not apply coupon with individual use coupon already applied
         if ($woocommerce->cart->applied_coupons) {
             foreach ($woocommerce->cart->applied_coupons as $code) {
                 $coupon = new WC_Coupon($code);
                 if ($coupon->individual_use == 'yes') {
                     return false;
                 }
             }
         }
         $woocommerce->cart->applied_coupons[] = apply_filters('woocommerce_coupon_code', $this->opt['settings']['cart_discount_title']);
         return true;
     }
 }
开发者ID:baden03,项目名称:access48,代码行数:24,代码来源:wc-dynamic-pricing-and-discounts.php


示例13: ins_get_categories

$categories = ins_get_categories();
$products = ins_get_products();
$cart_items = $woocommerce->cart->cart_contents;
?>

<div class="add_discount" style="padding-top:1em; border-collapse:unset; font-size: 12px;">
  <h2 class="label">Add A Coupon</h2>
  <table id="coupons" style="border-bottom:1px solid #333;">
    <tr>
      <td class="coupon"><label for="coupon_select">Select a Coupon</label></td>
      <td class="coupon"><select class="chosen_select" style="width:200px;" id="coupon_select" data-placeholder="Select a Coupon" onblur="get_discount_info();" style="width:300px;">
        <option></option>
        <?php 
if ($coupons) {
    foreach ($coupons as $coupon) {
        $coupon = new WC_Coupon($coupon->post_title);
        if (!$woocommerce->cart->has_discount($coupon->code) && $coupon->is_valid()) {
            ?>
        <option value="<?php 
            echo esc_attr($coupon->code);
            ?>
"><?php 
            echo esc_html($coupon->code);
            ?>
</option>
        <?php 
        } else {
            var_dump($coupon->error_message);
        }
    }
}
开发者ID:jusmark123,项目名称:instore-Dev,代码行数:31,代码来源:instore-add-disc-html.php


示例14: decrease_coupon_usage_counts

 /**
  * Decrease applied coupon counts
  *
  * @access public
  * @return void
  */
 public function decrease_coupon_usage_counts()
 {
     global $woocommerce;
     if (get_post_meta($this->id, '_recorded_coupon_usage_counts', true) != 'yes') {
         return;
     }
     if (sizeof($this->get_used_coupons()) > 0) {
         foreach ($this->get_used_coupons() as $code) {
             if (!$code) {
                 continue;
             }
             $coupon = new WC_Coupon($code);
             $coupon->dcr_usage_count();
         }
     }
     delete_post_meta($this->id, '_recorded_coupon_usage_counts');
 }
开发者ID:googlecode-mirror,项目名称:wpmu-demo,代码行数:23,代码来源:class-wc-order.php


示例15: format_posts_to_items

 /**
  * Format posts from WP_Query result to items in which each item contain
  * common properties of item, for instance `post_title` will be `code`.
  *
  * @since  2.5.0
  * @param  array $posts Array of post
  * @return array Items
  */
 protected function format_posts_to_items($posts)
 {
     $items = array();
     foreach ($posts as $post) {
         $coupon = new WC_Coupon();
         $coupon->read($post->ID);
         $coupon_usage_limit = $coupon->get_usage_limit();
         $coupon_usage_limit_per_user = $coupon->get_usage_limit_per_user();
         $coupon_date_expires = $coupon->get_date_expires();
         $items[] = array('id' => $post->ID, 'code' => $post->post_title, 'type' => $coupon->get_discount_type(), 'created_at' => $this->format_datetime($post->post_date_gmt), 'updated_at' => $this->format_datetime($post->post_modified_gmt), 'amount' => wc_format_decimal($coupon->get_amount(), 2), 'individual_use' => $coupon->get_individual_use(), 'product_ids' => implode(', ', is_array($coupon->get_product_ids()) ? $coupon->get_product_ids() : array()), 'exclude_product_ids' => implode(', ', is_array($coupon->get_excluded_product_ids()) ? $coupon->get_excluded_product_ids() : array()), '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->get_limit_usage_to_x_items(), 'usage_count' => (int) $coupon->get_usage_count(), 'expiry_date' => !empty($coupon_date_expires) ? $this->format_datetime($coupon_date_expires) : null, 'free_shipping' => $coupon->get_free_shipping(), 'product_category_ids' => implode(', ', is_array($coupon->get_product_categories()) ? $coupon->get_product_categories() : array()), 'exclude_product_category_ids' => implode(', ', is_array($coupon->get_excluded_product_categories()) ? $coupon->get_excluded_product_categories() : array()), 'exclude_sale_items' => $coupon->get_exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->get_minimum_amount(), 2), 'maximum_amount' => wc_format_decimal($coupon->get_maximum_amount(), 2), 'customer_emails' => implode(', ', is_array($coupon->get_email_restrictions()) ? $coupon->get_email_restrictions() : array()), 'description' => $post->post_excerpt);
     }
     return $items;
 }
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:21,代码来源:class-wc-cli-coupon.php


示例16: is_available

 /**
  * 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


示例17: prepare_item_for_database

 /**
  * Prepare a single coupon for create or update.
  *
  * @param WP_REST_Request $request Request object.
  * @return WP_Error|stdClass $data Post object.
  */
 protected function prepare_item_for_database($request)
 {
     global $wpdb;
     $id = isset($request['id']) ? absint($request['id']) : 0;
     $coupon = new WC_Coupon($id);
     $schema = $this->get_item_schema();
     $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
     // BW compat
     if ($request['exclude_product_ids']) {
         $request['excluded_product_ids'] = $request['exclude_product_ids'];
     }
     if ($request['expiry_date']) {
         $request['date_expires'] = $request['expiry_date'];
     }
     // Validate required POST fields.
     if ('POST' === $request->get_method() && 0 === $coupon->get_id()) {
         if (empty($request['code'])) {
             return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400));
         }
     }
     // Handle all writable props
     foreach ($data_keys as $key) {
         $value = $request[$key];
         if (!is_null($value)) {
             switch ($key) {
                 case 'code':
                     $coupon_code = apply_filters('woocommerce_coupon_code', $value);
                     $id = $coupon->get_id() ? $coupon->get_id() : 0;
                     $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id);
                     if ($id_from_code) {
                         return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400));
                     }
                     $coupon->set_code($coupon_code);
                     break;
                 case 'meta_data':
                     if (is_array($value)) {
                         foreach ($value as $meta) {
                             $coupon->update_meta_data($meta['key'], $meta['value'], $meta['id']);
                         }
                     }
                     break;
                 case 'description':
                     $coupon->set_description(wp_filter_post_kses($value));
                     break;
                 default:
                     if (is_callable(array($coupon, "set_{$key}"))) {
                         $coupon->{"set_{$key}"}($value);
                     }
                     break;
             }
         }
     }
     /**
      * Filter the query_vars used in `get_items` for the constructed query.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
      * prepared for insertion.
      *
      * @param WC_Coupon       $coupon        The coupon object.
      * @param WP_REST_Request $request       Request object.
      */
     return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request);
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:69,代码来源:class-wc-rest-coupons-controller.php


示例18: apply_subscription_discount_before_tax

 /**
  * Apply sign up fee or recurring fee discount before tax is calculated
  *
  * @since 1.2
  */
 public static function apply_subscription_discount_before_tax($original_price, $cart_item, $cart)
 {
     global $woocommerce;
     $product_id = $cart_item['data']->is_type(array('subscription_variation')) ? $cart_item['data']->variation_id : $cart_item['data']->id;
     if (!WC_Subscriptions_Product::is_subscription($product_id)) {
         return $original_price;
     }
     $price = $original_price;
     $calculation_type = WC_Subscriptions_Cart::get_calculation_type();
     if (!empty($cart->applied_coupons)) {
         foreach ($cart->applied_coupons as $code) {
             $coupon = new WC_Coupon($code);
             if ($coupon->apply_before_tax() && $coupon->is_valid()) {
                 $apply_sign_up_coupon = $apply_sign_up_percent_coupon = $apply_recurring_coupon = $apply_recurring_percent_coupon = $apply_initial_coupon = $apply_initial_percent_coupon = false;
                 // Apply sign-up fee discounts to sign-up total calculations
                 if ('sign_up_fee_total' == $calculation_type) {
                     $apply_sign_up_coupon = 'sign_up_fee' == $coupon->type ? true : false;
                     $apply_sign_up_percent_coupon = 'sign_up_fee_percent' == $coupon->type ? true : false;
                     // Apply recurring fee discounts to recurring total calculations
                 } elseif ('recurring_total' == $calculation_type) {
                     $apply_recurring_coupon = 'recurring_fee' == $coupon->type ? true : false;
                     $apply_recurring_percent_coupon = 'recurring_percent' == $coupon->type ? true : false;
                 }
                 if (in_array($calculation_type, array('combined_total', 'none'))) {
                     if (!WC_Subscriptions_Cart::cart_contains_free_trial()) {
                         // Apply recurring discounts to initial total
                         if ('recurring_fee' == $coupon->type) {
                             $apply_initial_coupon = true;
                         }
                         if ('recurring_percent' == $coupon->type) {
                             $apply_initial_percent_coupon = true;
                         }
                     }
                     if (WC_Subscriptions_Cart::get_cart_subscription_sign_up_fee() > 0) {
                         // Apply sign-up discounts to initial total
                         if ('sign_up_fee' == $coupon->type) {
           

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WC_Email类代码示例发布时间:2022-05-23
下一篇:
PHP WC_Checkout类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap