• Resolved zaheer01

    (@zaheer01)


    I want to show the menu order field in a quick edit. I created a custom field that is showing correctly in the quick edit box, but the issue is how can I save the quick edit menu option to woocommerce product menu option? I tried some code without success.

    JQuery Code:

    jQuery(document).ready(function(){
    
    	jQuery(".acf-quick-edit input[type='text']").blur(function(){
    		var morder = jQuery(this).val();
    		var post_id = jQuery(this).parents("tr").attr("id");
    
    		var data = {
    			'action': 'update_menu_order',
    			'menu_order': morder,
    			'post_id':post_id
    		};
    
    		// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    		jQuery.post(ajaxurl, data, function(response) {
    			alert(response);
    		});
    
    	});
    
    	});

    PHP Code:

    <?php 
    
    	add_action( 'wp_ajax_update_menu_order', 'update_menu_order' );
    	add_action( 'wp_ajax_nopriv_update_menu_order', 'update_menu_order' );
    
    	function update_menu_order() {
    		global $wpdb; // this is how you get access to the database
    
    		$menu_order = $_POST['menu_order'];
    		$data = $_POST['post_id'];
    		$post_id = substr($data, strpos($data, "-") + 1);    
    	//print_r($_POST);
    	//echo get_post_field( 'menu_order', $post_id);
    	update_post_meta($post_id,'_menu_order',$menu_order);
    
    		
    
    		wp_die(); // this is required to terminate immediately and return a proper response
    	}
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey @zaheer01,

    You might take a look at this post:

    https://businessbloomer.com/woocommerce-add-custom-field-to-bulk-actions-edit/

    Previously I used it to add bulk edit for featured images. My wife needed a way to add the same featured image to multiple products at once. I suspect you could adapt it to work with the menu order as well.

    Cheers

    Thread Starter zaheer01

    (@zaheer01)

    I already achieved that but the issue was to update the menu options field when someone fills the custom field in a quick edit. I did not find any way so I start checking the database of the website, there I found the table wp_posts, every post has its menu order here I did the code below and everything starts working.

    <?php 
    add_action( 'wp_ajax_update_menu_order', 'update_menu_order' );
    add_action( 'wp_ajax_nopriv_update_menu_order', 'update_menu_order' );
    
    function update_menu_order() {
    global $wpdb; 
    $table_name = $wpdb->prefix."posts";
    
    $menu_order = $_POST['menu_order'];
    $data = $_POST['post_id'];
    $post_id = substr($data, strpos($data, "-") + 1);    
    
    $result = $wpdb->query($wpdb->prepare("UPDATE $table_name SET menu_order='$menu_order' WHERE ID=$post_id"));
    
    echo $result;
    
    wp_die(); // this is required to terminate immediately and return a proper response
    }
    Plugin Support abwaita a11n

    (@abwaita)

    Glad to hear it – thanks for letting us know as well as for sharing the code!

    I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new thread.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Menu order option in quick edit?’ is closed to new replies.