CF7 Ajax isn’t working when called inside WooCommerce “woocommerce_before_add_to_cart_button” hook [closed]

I am not sure when the woocommerce_before_add_to_cart_button action fires in the request sequence, but it could be worth adding the following code to your functions.php to see if it loads the CF7 js script files, add_action(‘wp_enqueue_scripts’, ‘pre_register_cf7_files’); function pre_register_cf7_files(){ wp_register_style(‘contact-form-7’, wpcf7_plugin_url( ‘includes/css/styles.css’ ), array(), WPCF7_VERSION, ‘all’ ); wp_register_script( ‘contact-form-7’, wpcf7_plugin_url( ‘includes/js/scripts.js’ ), array( ‘jquery’ ), … Read more

Compare $_POST returned values with term array

Just check if $_POST contains key with id of correstponding term. if (isset($_POST[‘recvid’][$term->term_id])) { However, I would not loop through all the terms. get_terms function has corresponding option. So, to receive all posted ids, you would do this (also note, that first parameter may be a string, no need for an array): $brands = get_terms(‘recipebrands’, … Read more

Can I make get_users() query global?

You can use the WordPress functions apply_filters and add_filters to store and retrieve data, like so: // The filter callback function. function so_wp_380975_get_user_args( $array ) { // (maybe) modify $array. // for now, we just return the array return [ ‘meta_key’ => ‘mycred_default’, ‘orderby’ => [ ‘meta_value_num’ => ‘DESC’ ], ‘order’ => ‘desc’, ‘number’ => … Read more

How to make a fetch() POST request to wordpress rest api?

‘X-WP-Nonce’ : Ajax.nonce Was missing that’s why it was giving the error fetch(‘https://mywebsite.online/wp-json/wp/v2/code’, { method: ‘POST’, credentials: ‘same-origin’, headers: new Headers({ ‘Content-Type’: ‘application/json;charset=UTF-8’, ‘X-WP-Nonce’ : Ajax.nonce }), body: JSON.stringify(OurPostData), }).then(response => { console.log(response); return response.json(); });

Data not insert and update through ajax and jQuery in admin page?

I see that there’s an internal server error (see screenshot) when you tried to update a record in the database, and the error is likely because you incorrectly called $wpdb->update() which has the syntax of — and note that the first three parameters ($table, $data and $where) are required: wpdb::update( string $table, array $data, array … Read more

AJAX jQuery post frontend returning failed to load resource status 400

There’s two problems that I see. Firstly, your add_action(‘wp_ajax_nopriv_get_question’,… code is inside your template, but your template is not going to be loaded when the request is sent to wp-admin/admin-ajax.php, which does not load templates. The callback code and the code that hooks it need to go in your theme’s functions.php file. Secondly, you have … Read more

Admin-ajax.php 400 error in custom theme

It seems that you’re adding the AJAX action only if $pagenow (the current admin page/file) is edit.php or post.php, and that’s not going to work on admin-ajax.php, so you should instead add the action via the admin_init hook if you wish to add the action only on the admin side. E.g. add_action( ‘admin_init’, function () … Read more