Categories
CMS Mastering Development Wordpress

How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)

I’m trying to make my own appointment system for WordPress. For this, I created a post type called "appointments". When users select a service from the service list, the available dates and times are listed. When the available date and time are selected and the appointment is created, a meta key named "appointment_datetime" is added […]

Categories
CMS Mastering Development Wordpress

Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin

I have a custom plugin with the following code add_action( ‘init’, ‘my_script_enqueuer’ ); function my_script_enqueuer() { wp_register_script( "gift_card_redeem", WP_PLUGIN_URL.’/plugin-folder/gift_card_redeem.js’, array(‘jquery’) ); wp_localize_script( ‘gift_card_redeem’, ‘myAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘gift_card_redeem’ ); } add_action("wp_ajax_gift_card_redeem", "gift_card_redeem"); function gift_card_redeem(){ if(!empty($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’) { error_log("test !empty"); $result[‘type’] = "success"; $result = json_encode($result); […]

Categories
CMS Mastering Development Wordpress

WP ajax requests not stacking?

My ajax requests work individually, (if I wait for each request to return before submitting the next), but if I submit a bunch of requests at the same time, (eg click multiple buttons), only the last action returns a response. It’s like each request is overwriting/cancelling out the previous one. I am using WP’s admin-ajax.php, […]

Categories
CMS Mastering Development Wordpress

WP ajax requests not stacking?

I managed to get Ajax requests working using WP’s admin-ajax.php, like so: <?php $nonce = wp_create_nonce("my_nonce"); $link = admin_url(‘admin-ajax.php?action=add_item&post_id=’.$post->ID.’&nonce=’.$nonce); echo ‘<a class="add_item" data-action="add_item" data-nonce="’ . $nonce . ‘" data-post_id="’ . $post->ID . ‘" href="’ . $link . ‘">add item</a>’; ?> and then some JS like this: $(".prod_btns a").click(function(e) { e.preventDefault(); var action = $(this).data("action"); var […]

Categories
CMS Mastering Development Wordpress

What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler? Q: Am I calling the php function correctly? Page Element The user clicks a button. Action: The click should connect to an external server using the following params: User Name 2. IP Address 3. Port 4. Public […]

Categories
CMS Development Wordpress

Ajax is not defined

Stack Exchange long time listener, first time caller. I have found examples on the developer.wordpress site but I have been still struggling. Localizing scripts: wp_localize_script() In my theme’s functions.php file, I have: function wp_my_ajax_script() { wp_localize_script( ‘ajax_handle_agent_search’, ‘myAjax’, admin_url( ‘admin-ajax.php’ )); wp_enqueue_script( ‘ajax_handle_agent_search’ ); } add_action( ‘wp_enqueue_scripts’, ‘wp_my_ajax_script’ ); And on my page, I’ve added […]

Categories
Development

WooCommerce Admin Order AJAX Not Getting Any Response?

Update: Issue resolved! The AJAX works but I had the function debug_to_console for testing which echo to the console log. Here is the function: /* This is a function to print data to web browser console ** ** Use debug_to_console( $data ); to print */ function debug_to_console( $data ) { $output = $data; if ( […]