简体   繁体   English

如何根据可用性更改WooCommerce添加到购物车按钮

[英]How to change WooCommerce Add to Cart Button based on Availability

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;
}

Add this code in your functions.php file 将此代码添加到您的functions.php文件中

暂无
暂无

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

相关问题 根据Woocommerce中的父产品类别更改“添加到购物车”按钮文本 - Change Add To Cart button text based on parent product categories in Woocommerce 根据 WooCommerce 产品类型更改添加到购物车按钮和文本 - Change add to cart button and text based on WooCommerce product type 在Woocommerce中根据IP地址(GeoLocation)更改添加到购物车按钮 - Change add to cart button based on IP-adress (GeoLocation) in Woocommerce 在 WooCommerce 简单产品的添加到购物车按钮中显示可用性 - Display availability in add to cart button for WooCommerce simple products 如何在 WooCommerce 中更改“添加到购物车”? - How to change "add to cart" in WooCommerce? WooCommerce 添加到购物车重定向基于点击的按钮 - WooCommerce add to cart redirect based on button clicked 在Woocommerce中单击后,将“添加到购物车”按钮更改为“查看购物车”按钮 - Change Add to Cart Button to View Cart Button after click in Woocommerce 删除Woocommerce中的“添加到购物车”通知并更改“添加到购物车”按钮 - Remove add to cart notice and change “add to cart” button in Woocommerce 当产品在 Woocommerce 的购物车中时,更改添加到购物车按钮样式 - Change add to cart button style when product is in cart in Woocommerce Woocommerce:购物车中已有物品时,更改“添加到购物车”按钮的颜色 - Woocommerce: Change “add to cart” button color when something is already in the cart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM