How to change WooCommerce Add to Cart Button based

2019-08-15 10:42发布

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

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-15 11:22
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

查看更多
登录 后发表回答