set_usage_count() public method

Set how many times this coupon has been used.
Since: 2.7.0
public set_usage_count ( integer $usage_count )
$usage_count integer
Esempio n. 1
0
 /**
  * Test coupon reading from the DB.
  * @since 2.7.0
  */
 function test_coupon_read()
 {
     $code = 'coupon-' . time();
     $coupon = new WC_Coupon();
     $coupon->set_code($code);
     $coupon->set_description('This is a test coupon.');
     $coupon->set_usage_count(5);
     $coupon->save();
     $coupon_id = $coupon->get_id();
     $coupon_read = new WC_Coupon($coupon_id);
     $this->assertEquals(5, $coupon_read->get_usage_count());
     $this->assertEquals($code, $coupon_read->get_code());
     $this->assertEquals('This is a test coupon.', $coupon_read->get_description());
 }
 /**
  * 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;
 }