I want to make it possible to control the order of goods, where tags, category, date, etc. go, in WooCommerce there is a function: Products - your_goods - in addition - Order menu (arbitrary ordering of positions) by 3 steps.

As you can see, the path is quite long, and it is extremely difficult to go through with each product when there are 1,000, 5,000, and so on.

I went to the docks of Woocommerce Hooks, there is nothing like that to hone the output of the table and add a column, a field in each product immediately on the page of all products.

Who edited the table WooCommerce Wordpress, tell me where to dig, how to do?

Perhaps there is a plugin, for editing the table of tutorials, and removing this field in the table.

  • add column
  • add field and button to update product
  • impose hooks on product updates according to the "Order Menu" criterion.

    1 answer 1

    All wrong. WooCommerce does not create any of its tables (look in the database). The product is a custom WordPress post, of type product (wp_posts table). Commodity fields are the metadata for this post (wp_postmeta table). Product price field (for example) is updated programmatically as follows:

    update_post_meta($id, '_price', $price); 

    But what you are asking about is the field of the post itself, in the wp_posts table. Updated as follows:

      $post->menu_order = $order; wp_update_post( $post ); 

    An example of code that can be inserted from functions.php to update all products in the database:

     function update_WC() { $args = array ( 'numberposts' => -1, 'post_type' => 'product'); $posts = get_posts( $args ); foreach( $posts as $post ) { $id = $post->ID; $order = ... ; $post->menu_order = $order; wp_update_post( $post ); $price = ... ; update_post_meta($id, '_price', $price); } } // add_action ('init', 'update_WC'); // for development purposes only 

    Keep in mind that the code will be called each time the site is accessed. Those. The line with add_action should be uncommented, refreshing any page of the site and quickly commenting this line back.