How To Override A WooCommerce AJAX Function

Ok, so I don’t know if this is the best way, but it’s working for now. Within my OOP class (I have a custom plugin to override a WC plugin): remove_action( ‘wp_ajax_wc_function’, array( WC_Parent_Class, ‘wc_do_stuff’ ) ); remove_action( ‘wp_ajax_nopriv_wc_function’, array( WC_Parent_Class, ‘wc_do_stuff’ ) ); add_action( ‘wp_ajax_wc_function’, array( __CLASS__, ‘my_override_do_stuff’ ) ); add_action( ‘wp_ajax_nopriv_wc_function’, array( __CLASS__, … Read more

Ajax form submit not working, returns 0

The action: ‘ajax_contact’ part in: var data = $form.serialize(); console.log(data); $.ajax({ url: ajax_contact.ajaxurl, dataType: ‘json’, action: ‘ajax_contact’, data: ajax_contact.data, is most likely the cause here, that your ajax request is failing. Move the action part into the data set instead. Since you’re serializing the form data, you could try to add: <input type=”hidden” name=”action” value=”ajax_contact” … Read more

is_single() conditional check inside ajax php function

is_single returns if there is a single page displayed within the actual server process. Within the Ajax-Function, nothing is “displayed”, you’re doing Ajax. To check if the currently displayed object in your Browser is a single object, you need to transfer the information about this from the server process that serves your Browser to the … Read more

HTML escaping data with ajax requests

If it is not HTML, it does not need HTML escaping, if it is not JS, it does not need JS escaping. All escaping is context based. In general You should probably just avoid sending “text” in response and focus on sending data which is “converted” into whatever is the relevant DOM structures, either directly … Read more

Making an AJAX call to refresh a table

The action in the Ajax call must be the name of the action on the add_action without the wp_ajax_nopriv.* for example: var data = { action: ‘fmsapi_refresh_hybrid_schedule’, year: ‘2017’, event: ‘ONOSH’, team: ‘4783’ }; You are targeting a class named select_team but this isn’t anywhere in your code. This is why your Js code cannot … Read more

Submit Form data to another page via Ajax (WordPress Way)

Modify the following code I have added action in it. $(‘#btnDoCalculation’).click(function(e){ var formData = $(‘#interest_calculator’).serialize(); $.ajax({ type: ‘POST’, url: ‘<?php echo admin_url(‘admin-ajax.php’);?>’, data:formData, dataType: ‘json’, action:calculate_investor_interest encode:true, }).done(function(data){ if(data.success){ console.log(data); var results = data.calc_results; var newData = results.reduce(function(collection, element){ var rowData = {}; //create a new empty row element.reduce(function(collection, element){ //put the elements into the … Read more