如何根据可用性更改 WooCommerce 添加到购物车按钮 [英] How to change WooCommerce Add to Cart Button based on Availability

查看:29
本文介绍了如何根据可用性更改 WooCommerce 添加到购物车按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将添加到购物车"按钮更改为进行查询",我希望将其链接到页面下方的一个选项卡或一个单独的页面.我希望此更改基于可用性或是否列出价格.我已经对如何有条件地更改链接和文本有了基本的了解,但不是基于参数和我需要的范围.

I am trying to have the "Add to Cart" button change to "Make an Inquiry" and I would like that to link to either a tab further down the page or to a separate page all together. I would like this change to be based on availibilty or whether or not the price is listed.I already have a basic understanding on how to change the link and text conditionally, but just not based on the parameters and to the scope I need.

我知道这个回复太晚了,但下面是我所拥有的.我的问题是它不在原来的添加到购物车按钮的位置,而且太宽了.

I know this response is incredibly late but below is what I have. The problem I have is that it is not in the position of the the original add to cart button, and its too wide.

add_action('woocommerce_single_product_summary','replace_add_to_cart');
    function replace_add_to_cart() {
    global $product;

        if ( ! $product->is_in_stock() ){
            remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
            add_action( 'woocommerce_single_product_summary','consult_bezambar_expert', 30 );

    function consult_bezambar_expert() {
    global $product;

        echo '<form action="' . esc_url($product->get_permalink( "#tab- reviews" )) . '" method="get">
            <button type="submit" class="single_add_to_cart_button button alt">Consult Bez Ambar Expert</button>
            </form>';
        }
    }
}

推荐答案

add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); 

function woo_custom_cart_button_text( $text ) 
{
    if( has_term( 'your-special-category', 'product_cat' ) )
    {
        $text = __( 'Make an Inquiry', 'your-plugin' );
    }
    return $text;
}

将此代码添加到您的functions.php文件中

Add this code in your functions.php file

这篇关于如何根据可用性更改 WooCommerce 添加到购物车按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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