简体   繁体   English

产品售罄时,我可以隐藏 WooCommerce 产品变体菜单吗?

[英]Can I hide the WooCommerce product variations menu when the product is sold out?

My site sells paintings, with the option of being framed or unframed.我的网站出售画作,可选择有框或无框。 The obvious way to do that seemed to be as product variations.这样做的明显方法似乎是产品变体。 But it's an unusual case, because of course the painting is unique and when either variation is sold the product should be out of stock.但这是一个不寻常的情况,因为这幅画当然是独一无二的,当任何一种变体出售时,产品都应该缺货。

I have the basics of that working now;我现在有基本的工作; the product will become unavailable once either variation is sold.一旦任一变体售出,该产品将不可用。 But unfortunately the option dropdown still displays, only showing "Out of Stock" after the visitor selects one or other variation.但不幸的是,选项下拉菜单仍然显示,仅在访问者选择一个或其他变体后显示“缺货”。 Which seems likely to annoy them.这似乎会惹恼他们。

So what I'm trying to do is hide this options menu and replace it with the standard "Out of Stock" message when the product [or either of its two variations] has been sold.因此,我要做的是隐藏此选项菜单,并在产品 [或其两种变体中的任何一种] 已售出时将其替换为标准的“缺货”消息。 But to my surprise I can't find anyone else who has had this problem, and writing such a function is beyond my own knowledge of PHP and WordPress.但令我惊讶的是,我找不到其他遇到此问题的人,而编写这样的 function 超出了我对 PHP 和 WordPress 的了解。

Similar question was asked here: Add a custom class to variation options displaying "Out Of Stock" in Woocommerce此处提出了类似的问题: Add a custom class to variant options display "Out Of Stock" in Woocommerce

You can use the answer from that thread to add a css class or append extra text to out of stock variations.您可以使用该线程的答案将 css class 或 append 额外文本添加到缺货变体中。
By using the added class you can also hide the items using css.通过使用添加的 class,您还可以使用 css 隐藏项目。

For anyone else with this issue, I found that I was looking at the problem in the wrong way.对于遇到此问题的其他人,我发现我以错误的方式看待问题。 Offering framing on a unique product like a painting is not truly a product variation, but something more akin to a delivery option.在像绘画这样的独特产品上提供框架并不是真正的产品变体,而是更类似于交付选项的东西。 As suggested by Lynn Greene here, what I really wanted was an optional extra for the product - a product add-on.正如 Lynn Greene 在这里所建议的那样,我真正想要的是该产品的可选附加组件 - 产品附加组件。

I found the free version of the plugin "Advanced Product Fields for WooCommerce" did this pretty simply.我发现插件“Advanced Product Fields for WooCommerce”的免费版本非常简单。

Variations in WooCommerce create a product for each variation. WooCommerce 中的变体为每个变体创建一个产品。 They are meant to be used when you have products that come in different varieties (small, medium, large, or blue, red, yellow, etc.)当您拥有不同品种(小、中、大或蓝色、红色、黄色等)的产品时,应使用它们。

The use case you're describing seems a better fit for a product add-on field.您描述的用例似乎更适合产品附加领域。 This would allow the customer to check a box or select an option, and pass the value of that option to you in the order details.这将允许客户选中一个框或 select 一个选项,并在订单详细信息中将该选项的值传递给您。 This lets you have one product listing per painting, but still allows the customer to select a framing option.这使您可以为每幅画提供一个产品列表,但仍允许客户为 select 提供框架选项。

You can do this with a plugin ( Product Addons for Woocommerce , Extra Product Options , etc.), or with your own code .您可以使用插件( Woocommerce 的产品插件额外的产品选项等)或使用您自己的代码来执行此操作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM