Php Woocommerce和条件语句删除缺货产品的购物车按钮
我试图在functions.php文件中编写一条条件语句,以检查某个项目是否有库存。现在,我正在使用以下代码将产品归档页面上的购物车按钮替换为数量标签和输入以及添加到购物车按钮,它们与单个产品页面中的按钮类似Php Woocommerce和条件语句删除缺货产品的购物车按钮,php,wordpress,function,woocommerce,Php,Wordpress,Function,Woocommerce,我试图在functions.php文件中编写一条条件语句,以检查某个项目是否有库存。现在,我正在使用以下代码将产品归档页面上的购物车按钮替换为数量标签和输入以及添加到购物车按钮,它们与单个产品页面中的按钮类似 remove_action( 'woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart'); //removes ajax Add To Cart button` add_action( 'w
remove_action( 'woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart'); //removes ajax Add To Cart button`
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 30); //replaces singluar cart button with QTY input as well as cart button
因为我想在产品缺货时让它们消失,所以我想我可以这样写:
function backorder_msg() {
global $product;
if ( $product->is_in_stock() ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); // remove that ajaxified Add To Cart button that automatically adds 1 item to the cart.
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 30); // replace it with the Add To Cart Button, complete with QTY field.. the same one that is used on the Single Product page.
} else {
}
add_action('get_header', 'backorder_msg');
现在,这显然不起作用。一个原因是因为我使用的get_头钩;我不知道在那里用什么。我也不确定在else语句中写什么。如果我删除这两个操作,那么该区域将恢复为默认的woocommerce购物车按钮,我希望该按钮也消失,并替换为一些文本。知道如何继续吗?woocommerce不是已经这样做了吗?@pguardiario知道怎么做吗?我的意思是,WC不应该为缺货项目显示“添加到购物车”。@pguardiairio可能是因为自定义操作而搞砸了。不管怎样,我们仍在寻找隐藏第二个操作的方法。使用jquery可以更轻松地隐藏它。