fetching via fetch/ajax gutenberg block data from third party

Well, I figured it out. Though my solution is probably far from elegant (I’m not making concessions for timeouts or usability/accessibility). My problem was mostly overzealous configuration, copy and paste errors, and needing to apply async/await keywords. Attributes look like this: attributes: { url: { source: ‘attribute’, type: ‘string’, selector: ‘.o_microlink’, attribute: ‘href’, }, title: … Read more

Ajax loop in sidebar to load post titles/categories

What is the script for you posted here? I hope it is not the script that will be called by the ajax request, isn’t it?? Normally a php script for an ajax request looks like this: <?php $output = array(); $posts = new WP_Query( array( ‘showposts’ => 20 ) ); foreach ( $posts as $post … Read more

Why is my ajax call refreshing the page?

Try using preventDefault(), it’s a jQuery function for preventing default actions called by the browser. First you should call an event handler by firing up your submitter. You can do this as follow: $(‘#my_upload_form’).submit(function (event) { After catching a submit and giving an event with it, you should prevent the default refresh of a browser: … Read more

wp_ajax action is not running

Where are you calling add_action()? If it’s in a place where you’re already outputting HTML, it’s too late, and that’s probably a place that wont even be looked at during an AJAX request. You should include that code in your theme’s functions.php file, or as early as possible in a plugin.

wp_localize_script, variable is not defined in jquery

wp_localize_script should be called AFTER wp_enqueue_script: IMPORTANT!: wp_localize_script() MUST be called after the script it’s being attached to has been enqueued or registered. It doesn’t put the localized script in a queue for later scripts. Fix it in your function: function my_action_callback() { wp_enqueue_script(‘jscustom’); // I assume you registered it somewhere else wp_localize_script(‘jscustom’, ‘ajax_custom’, array( … Read more

How to add default images into theme customizer image control?

Our journey starts here with the WP_Customize_Background_Image_Control class, which is a WP_Customize_Image_Control. I’d imagine offering these built-in backgrounds in a new tab alongside the existing Upload New and Uploaded tabs. There are at least two ways of achieving the following: either creating your own modified class based off of the WP_Customize_Background_Image_Control class, or altering its … Read more

WooCommerce add_to_cart() with custom price [closed]

Currently there is no straight way to add custom price to product which is added through function $woocommerce->cart->add_to_cart (Documentation) but we have a bypass way that i explain in code below global $woocommerce; $custom_price = 1000; // Cart item data to send & save in order $cart_item_data = array(‘custom_price’ => $custom_price); // woocommerce function to … Read more