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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.