WooCommerce AJAX cross domain add to cart

If you have enabled the CORS policy headers then you can directly add a product via link given below; Site-url.com/?add-to-cart=PRO-ID&variation_id=ATTR-ID&quantity=1&attribute_YOUR-ATTR-NAME=ATTR-VALUE Trigger this url for an ajax / windows location on an action in your javascript.

using ajax to query sql

See documentation WordPress have admin-ajax.php file in wp-includes/ folder. Put in your data parametr action and create hooks: add_action(‘wp_ajax_{your_action}’, ‘handler’); add_action(‘wp_ajax_nopriv_{your_action}’, ‘handler’); ajax.url parametr you can get by using wp_localize_script(‘YOUR SCRIPT handle’, ‘ajax’, array(‘url’=> admin_url(‘admin-ajax.php’))) All code must looks like: add_action( ‘wp_enqueue_scripts’, ‘callback_for_setting_up_scripts’ ); function callback_for_setting_up_scripts() { wp_register_style( ‘mein-plugin’, plugins_url( ‘style.css’, __FILE__ ) ); wp_enqueue_style( … Read more

what’s the way to access variables from serializeArray

You should be getting the data from the $_POST server variable, not the $_REQUEST eg. (isset($_POST)) { $postData = $_POST[‘post_data’]; } $_REQUEST doesn’t force you to figure out if the variable came from GET, POST, COOKIES, etc. It’s useful for debugging scripts or when the variable might come form one of several sources. For instance … Read more

WordPress blocking polling request when signed into Admin

Hence, ajax calls that must be triggered from within the wp admin panel should be registered via the wp_ajax_{$action} hook, and ajax calls that are triggered from the frontend and have totally nothing to do with wp-admin, but are like simple REST interactions of your platform users with your platform server, should be registered via … Read more

WordPress & Ajax

This link to the WordPress Codex should help. It demonstrates a few different ways to POST using AJAX in a plugin. As for re-arranging your listed elements, this can be done a number of ways. I would recommend running a search for rearranging elements using javascript. The jQuery function .insertBefore() and .insertAfter() can be used … Read more

Can’t access data from database using AJAX

Pass data as an argument in done(function(data) funtion. <script> jQuery.ajax({ type:”POST”, url: my_ajax_object.ajax_url, data: { ‘action’: ‘call_my_ajax_handler’ } }).done(function(data) { console.log(data); });

Disable Ajax for Spiders

Here’s a programatic method. What it does it checks if an ajax request is running and if the useragent to see if it is in the defined whitelist and if it is then it continues loading wp as normal, else it dies. I used registered_taxonomy because it’s the second hook in the hook loading processes: … Read more

wp_editor() in content that was loaded with ajax [duplicate]

Solution: Add wp_editor() in somewhere that works perfectly and hide it. <div class=”hidden-editor-container” style=”display:none;”> <?php wp_editor( ”, ‘editor’ ); ?> </div> after that assign editor contents to the global JS variable. EDITOR = $(‘.hidden-editor-container’).contents(); Finally when the ajax page is loaded append editor contents $(‘.editor’).append( EDITOR ); tinymce.execCommand( ‘mceRemoveEditor’, false, ‘editor’ ); tinymce.execCommand( ‘mceAddEditor’, false, … Read more