隐藏“加入购物车"产品价格为零时的按钮 [英] Hide "Add to cart" button when the product price is zero

查看:17
本文介绍了隐藏“加入购物车"产品价格为零时的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于活动的 WordPress 网站,我在该网站上使用 WooCommerce 销售门票.有没有办法隐藏成本为零的产品的添加到购物车"按钮?

I have an event based WordPress website on that I sell tickets using WooCommerce. Is there any way to hide the "add to cart" button for the product having cost zero?

谢谢.

推荐答案

您在主题中编写此代码 function.php

You write this code in your theme function.php

function remove_add_to_cart_on_0 ( $purchasable, $product ){
        if( $product->get_price() == 0 )
            $purchasable = false;
        return $purchasable;
    }
    add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_on_0', 10, 2 );

这篇关于隐藏“加入购物车"产品价格为零时的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆