There is a bunch: WooCommerce + Woocommerce Simple Auctions. It is necessary in my body of the created plug-in to sort the goods, select only those that are auctions and change the desired values ​​of the auction without bringing it to the front-end.

The problem is that when I use the standard product cycle, it does not contain the necessary properties and meta-fields that relate to the auction. Those. they belong to the WC_Product_Simple class, but they should belong to the WC_Product_Auction. The thought arose that I was just hooking my loop on the wrong hook.

enter image description here

  • I think the hook has nothing to do with it. You are using a fairly late one: codex.wordpress.org/Plugin_API/Action_Reference Usually, all initialization takes place at init. Auction plugin paid, set to study will not work. Judging by the screenshots on Envato, auctions are commodities, yes (there was initially a doubt about this). But, most likely, they are hidden when outputting in a loop by changing the WC cycle. Try adding 'suppress_filters' => true wp-kama.ru/hook/posts_where to the parameters of your request - KAGG Design
  • @KAGGDesign No, unfortunately, it did not work. In the plugin code I found that the WC_Product_Auction class inherits from WC_Product. Tell me, maybe in what direction to dig? I used this pastebin.com/fV33s8Gr code to display the bid buttons on a product, so when I print print_r ($ product), everything is OK, I have access to the necessary properties and WC_Product_Auction Object. - SunnyBunny
  • Output in the code on your image just print_r ($ product); and see what happens. In general, it is hard to guess without seeing the plugin code. - KAGG Design
  • @KAGGDesign it displays WC_Product_Simple Object. The plugin can be found in the public domain, for example here downloadfreethemes.cc/woocommerce-simple-auctions-v1-2-20 I would be incredibly grateful for the help! - SunnyBunny

1 answer 1

As I assumed from the very beginning, the auction plugin filters the WP_Query request. In the wp-content/plugins/woocommerce-simple-auctions/woocommerce-simple-auctions.php there is a pre_get_posts() function that suppresses the output of auctions. Having rummaged in the code, I found that if the query parameter 'auction_arhive' => true, , then the auction plugin disables its filters.

Here is a screen shot of the debugger, which shows that the current object in the loop has a WC_Product_Auction class.

enter image description here

If the parameter 'product_type' => 'auction', added to the request, then only auction items will be included in the selection from the database. The working code is:

 function sample_func() { global $post; $args = array( 'post_type' => 'product', 'posts_per_page' => - 1, 'auction_arhive' => true, 'product_type' => 'auction', ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) { $loop->the_post(); $id = $post->ID; $item = wc_get_product( $id ); } wp_reset_postdata(); } add_action( 'wp_loaded', 'sample_func' ); 
  • Thank you very much! You really helped out and helped! - SunnyBunny