Set a specific default stock quantity on all WooCommerce new products

For “New” simple products on admin, the following embedded jQuery script will: trigger and enable “Stock management” at product level, set the “Stock quantity” to “1”, set the “Low stock threshold” to “0”. The code: add_action( ‘admin_footer’, ‘new_product_stock_default_setting’ ); function new_product_stock_default_setting() { global $pagenow, $post_type; // Targeting new product page (admin) if( $pagenow === ‘post-new.php’ … Read more

Problem with WordPress Ajax form

Ok, after a lengthy discussion Edegist and I actually sorted this all out. Here’s a couple of the key factors that comprise the solution. One, we had to loop through all of the selected checkboxes to pass via AJAX. jQuery( document ).ready( function( $ ) { $( ‘.kvo_ajax_submit_button’ ).click( function( e ) { e.preventDefault(); var … Read more

WordPress 3.1 not compatible with jQuery Mobile?

Just a guess, but your error message indicates that WordPress is using jQuery 1.4.4. If you look at the jQuery Mobile website, they’re using 1.5. Have you tried using wp_enqueue_script to use a jQuery 1.5? You’d want to try something like: <?php function my_init_method() { if (!is_admin()) { wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js’); wp_enqueue_script( … Read more

Timepicker-addon doesn’t show – Datepicker works fine?

Figured out that I needed to have the right js dependencies declared. This code now works. Hope it helps someone else with the same problem. Key line array(‘jquery-ui-core’ ,’jquery-ui-datepicker’, ‘jquery-ui-slider’) Full `wp-enqueue’ code: function pbd_events_jquery_datepicker() { wp_enqueue_script( ‘jquery-ui-datepicker’, get_bloginfo(‘template_directory’) . ‘/jquery-ui-datepicker/jquery-ui-1.8.16.custom.min.js’, array(‘jquery’) ); wp_enqueue_script( ‘jquery-ui-timepicker-addon’, get_bloginfo(‘template_directory’) . ‘/jquery-ui-datepicker/jquery-ui-timepicker-addon.js’, array(‘jquery-ui-core’ ,’jquery-ui-datepicker’, ‘jquery-ui-slider’) ); wp_enqueue_script( ‘pbd-datepicker’, get_bloginfo(‘template_directory’) … Read more

Unable to get_the_content(); of a post in WordPress via AJAX

get_the_content() must be used inside the loop, or otherwise you’ll need to use setup_postdata(); providing the post object. Try the following: function ajax_action_stuff() { $post_id = $_POST[‘post_id’]; //Query the post and set-up data $post = get_post($post_id); setup_postdata( $post ); update_post_meta($post_id, ‘post_key’, ‘meta_value’); //Return response as an array. This will give us data.title and data.content browser-side. … Read more

Modify this loop to fit my jQuery slider (slides)

Tried very simple math. <div class=”slide”> will print after every 4 post. So, if statement with old school logic $i%4 == 0 <div class=”slides_container”> <?php $args = array( ‘post_type’ => ‘fastighet’, ‘numberposts’ => -1, ‘orderby’ => ‘ASC’ ); $posts = get_posts($args); ?> <?php $i = 0; foreach($posts as $post): ?> <?php if($i%4 == 0): ?> … Read more

Ajax pagination works only first and third time

@kennypu in stackoverflow saved my life with this: t’s because you’re changing the contents of #paginar, so what happens is the event on the links are getting cleared. depending on your jquery version, you can either use .live() or add the even to the #pagi-container instead: $(‘#pagi-container’).on(‘click’,’#paginar > a’,function() {… } my finished code is … Read more

jQuery Validate wp_editor

Per the jQuery noConflict Wrappers section of the wp_enqueue_script() Codex page, the $ variable is not available in WordPress. You can replace $ with jQuery in your jQuery code, or do something like this: jQuery(document).ready(function($) { // your code here . . . });