How to insert a record by clicking on the link using AJAX

If this is your request data for an AJAX POST: data: { action: ‘gs_order’, nonce_data: ajax_vars.nonce, product_groups: $(this).data(“pgid”), products: $(this).data(“pid”) }, Then you access product_groups and products like this: $data = [ ‘product_groups’ => $_POST[‘product_groups’], ‘products’ => $_POST[‘products’], ]; Just make sure you sanitize and escape the data as required. If they’re going to be … Read more

Get Author Post on author.php with AJAX

Author.php means you are looking at an archive of the author already, so why would you need to display posts by that author? Regardless, you can get the author ID from get_queried_object, which returns the whole user object. <?php $curauth = get_queried_object(); if($curauth && isset($curauth->ID)){ //…trigger ajax to pass ID via the data object } … Read more

Woocommerce add to cart quantity buttons with AJAX

I fixed it with some IDs add in function.php add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘quantity_inputs_for_loop_ajax_add_to_cart’, 10, 2 ); function quantity_inputs_for_loop_ajax_add_to_cart( $html, $product ) { if ( $product && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) { // Get the necessary classes $class = implode( ‘ ‘, array_filter( array( ‘button’, ‘product_type_’ . $product->get_type(), $product->is_purchasable() && … Read more

wordpress and add actions to button by coding

Try below method. <a id=”view_site_description” href=”https://wordpress.stackexchange.com/questions/365101/javascript:void(0);”>View Our Site Description</a> add_action( ‘wp_footer’, ‘add_js_to_wp_footer’ ); function add_js_to_wp_footer(){ ?> <script type=”text/javascript”> jQuery(‘#view_site_description’).click(function(){ jQuery.ajax({ type: ‘POST’, url: ajaxurl, data: {“action”: “myfilter”}, success: function(data){alert(data);} }); return false; }); </script> <?php }