Categories

Wednesday, November 20, 2024
#919814419350 therichposts@gmail.com
WoocommerceWoocommerce HooksWordpressWordpress Cheat CodesWordpress HooksWordpress Tricks

Solved – WooCommerce Coupon Usage Limit has been Reached

Solved - WooCommerce Coupon Usage Limit has been Reached

Hello guys how are you? Welcome back on my blog therichpost.com. Guys today in this blog post you will see, Solved – WooCommerce Coupon Usage Limit has been Reached.

  1. WooCommerce Hooks
  2. WordPress Tricks
  3. WordPress Hooks
  4. Dokan

Guys there two methods to solve this kind of issue and here are they:

  1. Navigate to Coupons:
  • Go to WooCommerce > Coupons.
  1. Edit the Coupon:
  • Find the coupon in question and click on its name to edit it.
  1. Check or Adjust Usage Limits:
  • In the Usage limits tab, you can view and modify the usage restrictions:
    • Usage limit per coupon: The maximum number of times this coupon can be used by all customers.
    • Usage limit per user: The maximum number of times this coupon can be used by a single customer.
  1. Save Changes:
  • After making any necessary adjustments, click the Update button to save the changes.
add_action('woocommerce_coupon_used', 'increase_coupon_usage_limit');

function increase_coupon_usage_limit($coupon_code) {
    // Get the coupon object
    $coupon = new WC_Coupon($coupon_code);
    
    // Get the current usage limit
    $usage_limit = $coupon->get_usage_limit();
    
    // Increase the usage limit by 1
    if ($usage_limit) {
        $new_usage_limit = $usage_limit + 1;
        $coupon->set_usage_limit($new_usage_limit);
        $coupon->save();
    }
}

Explanation:

  • woocommerce_coupon_used: This hook is triggered every time a coupon is used.
  • increase_coupon_usage_limit: The function to handle the hook.
  • WC_Coupon($coupon_code): Create a coupon object using the coupon code.
  • get_usage_limit(): Get the current usage limit of the coupon.
  • set_usage_limit($new_usage_limit): Set the new usage limit.
  • save(): Save the coupon changes.

If you need further assistance or details about how to manage WooCommerce coupons, feel free to ask!

This is it guys and if you will have any kind of query, suggestion or requirement then feel free to comment below.

Jassa

Developer’s King

Thanks

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.