简体   繁体   English

显示和隐藏缺货变化 woocommerce

[英]Showing and hiding out of stock variations woocommerce

We have a unique situation whereby we need to show all variations of a product even if they are out of stock - this is because they are not technically out of stock - just not purchasable online.我们有一个独特的情况,我们需要展示产品的所有变体,即使它们缺货 - 这是因为它们在技术上没有缺货 - 只是不能在线购买。 However, when it comes to purchasing, the dropdown obviously should not show the variations that we have set to out of stock, because they cannot be purchased online.但是,在购买时,下拉菜单显然不应该显示我们设置为缺货的变体,因为它们无法在线购买。

Allowing them to be selected anyway, then an out os stock message being shown is very clunky and confusing for the user.无论如何都允许选择它们,然后显示的out os stock 消息对于用户来说非常笨拙且令人困惑。

Is there a woocommerce function, perhaps to get all variations rather than the default get_available_variations() ?是否有 woocommerce 功能,也许是为了获取所有变体而不是默认的get_available_variations()

Currently we have Hide out of stock items from the catalog selected, so that they do not appear in the purchase dropdown , and then the following for where we need to display the info anyway: content-single-product.php (child theme)目前我们已经选择的目录中隐藏缺货项目,以便它们不会出现在购买下拉列表中,然后我们需要在以下位置显示信息: content-single-product.php(子主题)

<?php

     global $product;

     $variations = $product->get_available_variations();


        if (!empty($variations)){

            foreach ($variations as $variation) {
                $id = $variation['variation_id'];
                echo $variation['attributes']['attribute_pa_delivery-method'] . '<br>';
                echo $variation['duration'] . '<br>';
                echo $variation['capacity'];

            }

        }

?> 

The other option of course, is to uncheck 'Hide out of stock items from the catalog', and somehow prevent the variation from appearing in the purchase dropdown instead.当然,另一种选择是取消选中“从目录中隐藏缺货商品”,并以某种方式防止变体出现在购买下拉列表中

Thanks in advance.提前致谢。

you can simply disable the "out of stock" using this snippet您可以使用此代码段简单地禁用“缺货”

add_filter( 'woocommerce_variation_is_active', 'grey_out_variations_when_out_of_stock', 10, 2 );
function grey_out_variations_when_out_of_stock( $grey_out, $variation ){
if ( ! $variation->is_in_stock() ){
  return false;
 }else{
  return true;
 }
}

( source ) 来源

then simply hide it with this CSS code然后简单地用这个 CSS 代码隐藏它

.variations option:disabled {
  display:none;
}

Hope that helps!希望有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果 WooCommerce 中的一个变体缺货,则将所有变体设置为缺货 - Set all variations out of stock if one variation is out of stock in WooCommerce woocommerce-显示库存变化 - woocommerce - display variations in stock 如果 WooCommerce 中的所有变体都缺货,则显示已售罄的灰色按钮 - Display a Sold out greyed button if all variations are out of stock in WooCommerce 显示用于 woocommerce 缺货产品变体的自定义 div 块 - Display a custom div block for woocommerce out of stock product variations 向显示为色板的变体添加“缺货”类 - WooCommerce - Adding an “out-of-stock” class to variations shown as swatches - WooCommerce 如果所有变体都缺货,则从目录中隐藏 WooCommerce 可变产品 - Hide WooCommerce variable product from catalog if all variations are out of stock 通过 WooCommerce 中的自定义库存数量减少来灰显“缺货”产品变化 - Greying out “out-of-stock” product variations with custom stock quantity reduction in WooCommerce WooCommerce 产品在实际没有缺货时显示“缺货”消息 - WooCommerce products showing “Out of stock” message when not actually out of stock 对于没有托管库存的 WooCommerce 变体显示“有货”通知 - Display “In Stock” notice for WooCommerce variations with no Managed Stock 显示在 WooCommerce 可变产品上售罄,当所有变体都缺货时 - Display sold out on WooCommerce variable product when all variations are out of stock
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM