Set “product_visibility” in Woocommerce to “out of stock” from outofstock metadata in _stock_status [closed]

最后都变了- 提交于 2020-05-16 22:00:22

问题


In WooCommerce I'm using scraping/import plugin which doesn't recognise and I can't insert outofstock meta based on actual stock in the "product_visibility" taxonomy.

The thing is, that all out of stock products are hidden when the stock status is Out of stock, but products are still counted in the product categories. If _stock_status product metadata is outofstock, the product_visibility outofstock post term should be also set for the product.

My Question is:
How to set the missing product_visibility outofstock post term when the product _stock_status metadata is set as outofstock?

I was trying something with code below. I'm not a programmer, but my logic was to get term in _stock_status... but It doesn't work :/

function wc_update_300_product_visibility() {
  global $wpdb;

  WC_Install::create_terms();

  $featured_term = get_term_by( 'name', 'outofstock', '_stock_status' );

  if ( $outofstock_term ) {
    $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = 'product_visibility' AND meta_value = 'yes';", $featured_term->term_taxonomy_id ) );
  }
}


来源:https://stackoverflow.com/questions/61509962/set-product-visibility-in-woocommerce-to-out-of-stock-from-outofstock-metada

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!