简体   繁体   English

产品缺货时删除按钮 Elementor PRO/Woocommerce

[英]Remove button when product out of stock Elementor PRO/Woocommerce

I'd really appreciate some help if anyone knows the solution :)如果有人知道解决方案,我将非常感谢您的帮助:)

I set up Product page template in Elementor Pro for Woocommerce product.我在 Elementor Pro 中为 Woocommerce 产品设置了产品页面模板。 I added a custom button there "Reserve now" (class .reserve-button) which opens a stripe payment form.我在那里添加了一个自定义按钮“立即预订”(类 .reserve-button),它打开了一个条纹支付表单。 I'd like to hide this button if the product is out of stock.如果产品缺货,我想隐藏此按钮。

I've tried a dozen of different solutions and searched through lot of fourms, but Im really stuck :(我已经尝试了十几种不同的解决方案并搜索了很多四个,但我真的卡住了:(

Here is one of them:这是其中之一:

add_action( 'woocommerce_before_add_to_cart_button', function() {
global $product;
if ( !$product->is_in_stock() ) {?>
<style>
.reserve-button {
display: none;}
</style> <?php 
}

});

Thank you in advance!先感谢您!

It seems every conditions you made properly but one thing that you missed is you added with a wrong action, because the woocommerce_before_add_to_cart_button action only fire when the button is enable, as you are checking with out of stock product and in that product there is no add to cart button, so your action is not fired ever.似乎您所做的每个条件都正确,但您错过的一件事是您添加了错误的操作,因为woocommerce_before_add_to_cart_button操作仅在按钮启用时触发,因为您正在检查缺货产品并且在该产品中没有添加到购物车按钮,因此您的操作永远不会被触发。 What you can do to add any other action like my code您可以做些什么来添加任何其他操作,例如我的代码

add_action( 'woocommerce_single_product_summary', function() {
    global $product;
    if ( !$product->is_in_stock() ) {?>
        <style>
        .reserve-button {
            display: none;
        }
        </style> <?php  
    }
    
});

Here I have added the style with the product summary action.在这里,我添加了带有产品摘要操作的样式。 You can choose any other action but not add to cart related any actions.您可以选择任何其他操作,但不能添加到购物车相关的任何操作。 Hope it will work for you.希望它对你有用。 https://prnt.sc/5fGq-RFcaEFn . https://prnt.sc/5fGq-RFcaEFn

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

相关问题 如果 Woocommerce 商店和档案缺货,请删除产品按钮 - Remove product button if out of stock from Woocommerce shop and archives 当 WooCommerce 档案中的产品缺货时删除自定义数量字段 - Remove custom quantity field when product out of stock on WooCommerce archives WooCommerce 缺货时的“联系”按钮 - WooCommerce “CONTACT” button when out of stock 如何在woocommerce中为缺货产品启用“添加到购物车”按钮? - How to enable add to cart button for out of stock product in woocommerce? 隐藏在Woocommerce中变量产品缺货时添加到购物车块 - Hide Add to cart block when a variable product is out of stock in Woocommerce 在 WooCommerce 中产品缺货时更改单个添加到购物车文本 - Change single add to cart text when product is out of stock in WooCommerce Woocommerce 商店产品缺货的日期和时间 - Woocommerce store date and time when the product went out of stock 当产品在Woocommerce中处于缺货状态时,显示“ Out of stock”标签 - Show “out of stock” label when product is on backorders in Woocommerce 仅在具有 Elementor 的小部件上隐藏缺货 WooCommerce 产品 - Hide out of stock WooCommerce products only on a widget with Elementor 在 woodmart 主题(元素网格或轮播)中隐藏缺货产品 - hide out of stock product in woodmart theme (elementor grid or carousel)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM