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

389
Views
How to use Woocommerce WC_AJAX class

I am developing a shop based on Wordpress WooCommerce. I use ajax to make calls for data. But i'm doing it with my own functions in function.php file via wp-admin/admin-ajax.php.

Yesterday I have found in woocommerce class WC_AJAX. My Question is how to enable events from that class, and how to call them from js.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

PHP - Do not wrap in if(is_admin()) like regular WP ajax actions. WC ajax is for front-end calls without the overhead of admin:

add_action('wc_ajax_myaction','myaction');
function myaction(){
    exit("Hello. some_var=".$_POST['some_var']);
}

JS - The URL to load is https://example.com/?wc-ajax=myaction which can be called with a standard XMLHttpRequest or jQuery:

var data={
    some_var:'some value'
}
jQuery.post('/?wc-ajax=myaction',data)
.done(function(result){
    console.log('ajax request completed. result=',result);
})
.fail(function(){
    console.log('ajax request failed. check network log.');
});
over 4 years ago · Santiago Trujillo Report
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!