WooCommerce REST API AJAX Auth – 401 response

First off, the WooCommerce REST API documentation is available here and you should check it out. Secondly, the examples below are using the /wc/v3/products/categories (“List all product categories“) endpoint. And here’s a proper way to authenticate your request using OAuth — it always works when authenticating over HTTPS and it is the only accepted option … Read more

404 error custom post type rest api

You need to declare that your CPT supports REST via show_in_rest when registering it, then use the REST API endpoint for that post type. For example, I have a CPT on my own site for talks named tomjn_talks, and it has an endpoint at /wp/v2/tomjn_talks

wp-admin/admin-ajax.php 400 (Bad Request) plugin

You’re only hooking your AJAX response inside wp_head(): function rp_add_header() { if (is_single() || is_page()) { // etc. add_action( ‘wp_ajax_ajax_action’, ‘ajax_action_stuff’ ); // ajax for logged in users add_action( ‘wp_ajax_nopriv_ajax_action’, ‘ajax_action_stuff’ ); // ajax for not logged in users } } add_action(‘wp_head’,’rp_add_header’,1); But wp_head doesn’t run on admin-ajax.php, so your callbacks will never be hooked. … Read more

Conditionally load public and admin code with AJAX working on both sides

I managed to resolve this issue by also checking for public interface. I created new function isPublic() to check if it is public. So here is my final code: if ($this->isPublic()) { require_once(plugin_dir_path(dirname(__FILE__)) . ‘public/class-public.php’); $this->Public = new Public(); } elseif ($this->isAdmin()) { require_once(plugin_dir_path(dirname(__FILE__)) . ‘admin/class-admin.php’); $this->Admin = new Admin(); } and here are helper … Read more

400 Bad Request getting on AJAX Call

Your have to use full url of ajax function. I have use ajax_url in your Ajax Call – footer.php(theme footer) file code. <script> var ajax_url = “<?php echo admin_url( ‘admin-ajax.php’ ); ?>”; jQuery(function() { jQuery(“#calc_form”).on(“submit”, function(e) { // alert(“submit”); e.preventDefault(); jQuery.ajax({ method: “POST”, url: ajax_url, data: { action: ‘calculation’, message_id: jQuery(‘#tot_tax_three_month_Input’).val() }, dataType: ‘json’, success: … Read more