Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Woocommerce ajax coupon link

I have created coupon links for Woocommerce with this:

function coupon_links()
{
    if (!function_exists('WC') || !WC()->session) {
        return;
    }   

    $query_var = apply_filters('woocommerce_coupon_links_query_var', 'coupon');
    if (empty($_GET[$query_var])) {
        return;
    }

    WC()->session->set_customer_session_cookie(true);
    if (!WC()->cart->has_discount($_GET[$query_var])) {
        WC()->cart->add_discount($_GET[$query_var]);
    }
}

add_action('wp_loaded', 'coupon_links', 30);
add_action('woocommerce_add_to_cart', 'coupon_links');

I need this in order to auto-apply a specific coupon when the user clicks on a link on the cart page. While it works, it is not ajax loaded. How can I make this link ajax so that the cart page does not refresh, but instead just ajax load like when you remove a coupon?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!