[英]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.