K
K
Konstantin Fedoev2016-03-31 05:45:55
PHP
Konstantin Fedoev, 2016-03-31 05:45:55

How to remove missing products from woocommerce?

Hello! There was such a question. I use an online store on WooCommerce, let's say there are a lot of goods (20.000+) I have
a question. I would like to remove goods that are NOT in stock (but they are displayed in the storefront with the indicator - 0 in stock)
And unfortunately I just can't figure out how to implement this. Maybe someone came across?
-------------------------------------------------- -
There is a function "Manage balances".
--------------------------------------------------
I found this code
<?php
/**
* set the stock status for all products in your WooCommerce store
* return void
*/
function woocommerce_update_stock_status(){
global $wpdb;
// set all status for products with 0 or less stocked quantity
$sql = "UPDATE $wpdb->postmeta stock, (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_stock' AND meta_value < 1 ) id SET stock. meta_value = 'outofstock' WHERE stock.post_id = id.post_id AND stock.meta_key = '_stock_status';";
// set all status for products with stock.
$sql .= "UPDATE $wpdb->postmeta stock, (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_stock' AND meta_value > 0 ) id SET stock.meta_value = 'outofstock' WHERE stock.post_id = id. post_id AND stock.meta_key = '_stock_status';";
// run queries
$wpdb->query( $sql );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LEXXiY, 2016-05-13
@DiazMoS

An excellent plugin for managing product offers for Woo is https://ru.wordpress.org/plugins/smart-manager-for... This is if you want to manage it manually.
If it’s automatic, then it’s worth reconsidering the work of displaying goods, for example, excluding the selection of goods with the presence of less than 1 in the cycle. Actually, the piece of code with the field is in the version you presented
meta_key = '_stock' AND meta_value < 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question