update_post_meta using ajax

You didn’t set a name attribute in your input tag with the id = “amount”. Set the name as “inpAmount” and try again. <input id=”amount” class=”inpAmount” type=”text” maxlength=”15″ /> should be <input id=”amount” class=”inpAmount” type=”text” maxlength=”15″ name=”inpAmount” /> As previously mentioned, the path to admin-ajax.php looks wrong as well. The wp_ajax nomenclature is also incorrect. … Read more

AJAX pagination, update current page

When you refresh the page, there is currently no state you can use to know you’re on page 2. You could use the History API to update the page URL without refreshing the page: history.pushState(data, title, ‘https://yourpage.com/?page=2’); You can also set some state on the user browser using the SessionStorage instead of the LocalStorage API, … Read more

In WooCommerce product archive, how can you also set the quantity to be added to cart by typing, instead of just by using +/-?

If using this plugin instead of the theme functionality, and in the same time except jquery from minification and grouping, it works: Quantity Field on Shop Page for WooCommerce https://wordpress.org/plugins/quantity-field-on-shop-page-for-woocommerce/ It seems that jQuery has to be excepted from minification and grouping because otherwise the code starting with this gives an error: <script type=”text/javascript”>jQuery(‘.products .post-10 … Read more

How to handle 400 status in Ajax [duplicate]

This function will load the JS scripts: function test_ajax_load_scripts() { // load our jquery file that sends the $.post request wp_enqueue_script( “ajax-test”, plugin_dir_url( __FILE__ ) . ‘/ajax-test.js’, array( ‘jquery’ ) ); // make the ajaxurl var available to the above script wp_localize_script( ‘ajax-test’, ‘the_ajax_script’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action(‘wp_print_scripts’, ‘test_ajax_load_scripts’);

get_queried_object_id in AJAX

OK, let’s start from trying to understand, what get_queried_object function does. According to its Codex page: Retrieve the currently-queried object. For example: if you’re on a single post, it will return the post object if you’re on a page, it will return the page object if you’re on an archive page, it will return the … Read more