WordPress Admin AJAX Serialize

Instead of relying on bespoke/custom serialising, and the ancient admin AJAX, consider using JSON and the REST API, e.g.: add_action( ‘rest_api_init’, function () { register_rest_route( ‘ramkumar/v1’, ‘/test/’, array( ‘methods’ => ‘POST’, ‘callback’ => ‘ramkumar_rest_test’ ) ); } ); function ramkumar_rest_test( $request ) { $reviewer_notes = $request[‘reviewer_notes’]; $result = ….; return $result; // gets sent to … Read more

Update html tag class values based on Woocommerce product attribute dropdown selection [closed]

You can use the following to add/remove a customized class to #primary selector based on the selected product attribute “Color”: <script type=”text/javascript”> jQuery(function($){ var p = ‘#primary’, c = $(p).prop(‘class’), s=”select[name=”attribute_pa_color”]”; // On start if( $(s).val() !== ” ) { $(p).prop(‘class’, ‘background-‘+$(s).val()); } // On select (blur live event) $(s).blur( function() { var b = … Read more

class click counter save number

Made ajax call as a function to avoid the Console Error 400 Post. It opens the channel and I was able to get the parameters passed. counter.js jQuery(document).on(‘click’,’.counter’,function(e){ testAjax(the_ajax_script.ajaxurl); }); function testAjax(link) { $.ajax({ url: link, type: ‘post’, data: { ‘action’: ‘set_button_count’, ‘increase’ : ‘1’ }, success: function(data) { jQuery(‘.count’).html(data); } }); } In functions.php … Read more

Unable to uncheck checkbox with jquery in wp admin

Can you please clarify your question? Are you attempting to make a checkbox that can clear all checkboxes and also recheck all checkboxes by checking that one checkbox? Also a checked input would be written like this: <input id=”editor-post-taxonomies-hierarchical-term-48″ class=”editor-post-taxonomies__hierarchical-terms-input” type=”checkbox” checked value=”48″ /> You can do this: $(‘div[aria-label=”Asukohad”] input[type=”checkbox”]’).on(“change”, function() { var element = … Read more

WooCommerce – Reset quantity input field when variation changes

To reset quantity input field to 1 when variation changes on product detail page use below code. you can set default quantity from jQuery(“[name=”quantity”]”).val(1);. i have tested and it is working fine for me. add_action( ‘wp_footer’, ‘variation_change_update_qty’ ); function variation_change_update_qty() { if (is_product()) { ?> <script> jQuery(function($){ $( “.variations_form” ).on( “woocommerce_variation_select_change”, function () { jQuery(“[name=”quantity”]”).val(1); … Read more

combine Code 1 with Code 2

Modified PHP code <?php // First, define these. $max_cat_count = 32; // this is ‘x’ $qty_per_column = 8; // this is ‘y’ // Then the $args array. $args = array( ‘taxonomy’ => ‘product_cat’, ‘number’ => $max_cat_count + 1, // keep the + 1 ‘hide_empty’ => 0, // … your other args here … ); // … Read more

js file in root loading without

WordPress has no mechanism to load custom js files automatically. If your theme need that js file, then place it inside your theme folder. and link it in your template file. for example, <script src=”https://wordpress.stackexchange.com/questions/353972/<?php echo get_template_directory_uri(); ?>/assets/bootstrap.min.js”></script> In the above example, “bootstrap.min.js” file is located in my theme’s “assets” folder. the function get_template_directory_uri() return … Read more