douchixu3686 2019-08-18 12:49
浏览 63

没有在产品页面上显示的复合产品库存

I have a few composite products on my webshop which is based on Woocommerce, but I only get the number of items in stock from the main product to be displayed.

For example I have 2 different couches on which the same type of pillow fits. If I want my stock to be adjusted correctly I need to make a composite product so the stock goes down on that pillow type wether they choose couch one or 2... (different than when you use variable products because then only the stock of that variation on that product goes down).

I've tried this code:

I've already tried to get data out of the database myself and tried contacting the developer of the plugin but they can't help me so I used the code below in hopes of fixing my problem, but that doesn't work. (it only shows the stock of the main product)

add_action('woocommerce_after_shop_loop_item','bbloomer_show_stock_shop', 
10);

function bbloomer_show_stock_shop() {
global $product;
if ( $product->stock ) { // if manage stock is enabled 
if ( number_format( $product->stock,0,'','' ) < 3 ) { // if stock is low
echo '<div class="remaining">Only ' . number_format($product->stock,0,'','') . ' left in stock!</div>';
} else {
echo '<div class="remaining">' . number_format($product->stock,0,'','') . ' left in stock</div>'; 
}
}
}

Here you can see an example: http://karup.qubeli.be/index.php/product/test-slaapbank/

I want the nr of stock of each option to be displayed (the options are stored as a variable product and yes the nr of stock of each variation is set).

So for example "5 in stock" below each option.

  • 写回答

0条回答 默认 最新

      编辑
      预览

      报告相同问题?

      手机看
      程序员都在用的中文IT技术交流社区

      程序员都在用的中文IT技术交流社区

      专业的中文 IT 技术社区,与千万技术人共成长

      专业的中文 IT 技术社区,与千万技术人共成长

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      客服 返回
      顶部