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


PHP WC_Coupon::save方法代碼示例

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


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

示例1:

 /**
  * Test coupon saving.
  * @since 2.7.0
  */
 function test_coupon_save()
 {
     $coupon = WC_Helper_Coupon::create_coupon();
     $coupon_id = $coupon->get_id();
     $coupon->set_code('dummycoupon2');
     $coupon->save();
     $coupon->read($coupon_id);
     // Read from DB to retest
     $this->assertEquals('dummycoupon2', $coupon->get_code());
     $this->assertEquals($coupon_id, $coupon->get_id());
     $new_coupon = new WC_Coupon();
     $new_coupon->set_code('dummycoupon3');
     $new_coupon->save();
     $new_coupon_id = $new_coupon->get_id();
     $this->assertEquals('dummycoupon3', $new_coupon->get_code());
     $this->assertNotEquals(0, $new_coupon_id);
 }
開發者ID:Korkey128k,項目名稱:woocommerce,代碼行數:21,代碼來源:crud.php

示例2: save

 /**
  * Save meta box data.
  *
  * @param int $post_id
  * @param WP_Post $post
  */
 public static function save($post_id, $post)
 {
     global $wpdb;
     // Check for dupe coupons
     $coupon_code = apply_filters('woocommerce_coupon_code', $post->post_title);
     $id_from_code = wc_get_coupon_id_by_code($coupon_code, $post_id);
     if ($id_from_code) {
         WC_Admin_Meta_Boxes::add_error(__('Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce'));
     }
     $coupon = new WC_Coupon($post_id);
     $coupon->set_props(array('code' => $post->post_title, 'discount_type' => wc_clean($_POST['discount_type']), 'amount' => wc_format_decimal($_POST['coupon_amount']), 'date_expires' => wc_clean($_POST['expiry_date']), 'individual_use' => isset($_POST['individual_use']), 'product_ids' => array_filter(array_map('intval', explode(',', $_POST['product_ids']))), 'excluded_product_ids' => array_filter(array_map('intval', explode(',', $_POST['exclude_product_ids']))), 'usage_limit' => absint($_POST['usage_limit']), 'usage_limit_per_user' => absint($_POST['usage_limit_per_user']), 'limit_usage_to_x_items' => absint($_POST['limit_usage_to_x_items']), 'free_shipping' => isset($_POST['free_shipping']), 'product_categories' => array_filter(array_map('intval', (array) $_POST['product_categories'])), 'excluded_product_categories' => array_filter(array_map('intval', (array) $_POST['exclude_product_categories'])), 'exclude_sale_items' => isset($_POST['exclude_sale_items']), 'minimum_amount' => wc_format_decimal($_POST['minimum_amount']), 'maximum_amount' => wc_format_decimal($_POST['maximum_amount']), 'email_restrictions' => array_filter(array_map('trim', explode(',', wc_clean($_POST['customer_email']))))));
     $coupon->save();
     do_action('woocommerce_coupon_options_save', $post_id);
 }
開發者ID:johnulist,項目名稱:woocommerce,代碼行數:20,代碼來源:class-wc-meta-box-coupon-data.php

示例3: update_post_meta_fields

 /**
  * Update post meta fields.
  *
  * @param WP_Post $post
  * @param WP_REST_Request $request
  * @return bool|WP_Error
  */
 protected function update_post_meta_fields($post, $request)
 {
     $coupon = new WC_Coupon($post->post_title);
     if (isset($request['amount'])) {
         $coupon->set_amount($request['amount']);
     }
     if (isset($request['individual_use'])) {
         $coupon->set_individual_use($request['individual_use']);
     }
     if (isset($request['product_ids'])) {
         $coupon->set_product_ids($request['product_ids']);
     }
     if (isset($request['exclude_product_ids'])) {
         $coupon->set_excluded_product_ids($request['exclude_product_ids']);
     }
     if (isset($request['usage_limit'])) {
         $coupon->set_usage_limit($request['usage_limit']);
     }
     if (isset($request['usage_limit_per_user'])) {
         $coupon->set_usage_limit_per_user($request['usage_limit_per_user']);
     }
     if (isset($request['limit_usage_to_x_items'])) {
         $coupon->set_limit_usage_to_x_items($request['limit_usage_to_x_items']);
     }
     if (isset($request['usage_count'])) {
         $coupon->set_usage_count($request['usage_count']);
     }
     if (isset($request['expiry_date'])) {
         $coupon->set_expiry_date($request['expiry_date']);
     }
     if (isset($request['free_shipping'])) {
         $coupon->set_free_shipping($request['free_shipping']);
     }
     if (isset($request['product_categories'])) {
         $coupon->set_product_categories($request['product_categories']);
     }
     if (isset($request['excluded_product_categories'])) {
         $coupon->set_excluded_product_categories($request['excluded_product_categories']);
     }
     if (isset($request['exclude_sale_items'])) {
         $coupon->set_exclude_sale_items($request['exclude_sale_items']);
     }
     if (isset($request['minimum_amount'])) {
         $coupon->set_minimum_amount($request['minimum_amount']);
     }
     if (isset($request['maximum_amount'])) {
         $coupon->set_maximum_amount($request['maximum_amount']);
     }
     if (isset($request['email_restrictions'])) {
         $coupon->set_email_restrictions($request['email_restrictions']);
     }
     $coupon->save();
     return true;
 }
開發者ID:pelmered,項目名稱:woocommerce,代碼行數:61,代碼來源:class-wc-rest-coupons-controller.php


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