I'm trying to add a custom link button that leads to Contact page - within first if condition that displays "Contact us" text with custom URL on the button instead of "Add to Basket" button.
How to do that? This is my code so far. It shows custom button text for each product which is part of category "64". That's exactly what I want. But how to add that button changes function from cart button to custom link button? Im figuring If have to change this cart buttons function. How?
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text() {
global $product;
$cat_id = 64;
$product->get_category_ids();
if ( in_array( $cat_id, $product->get_category_ids() ) ) {
return __( 'Contact us', 'woocommerce' );
}
else {
return __( 'Add to Basket', 'woocommerce' );
}
}
For your product category ID 64, the following code will replace add to cart button by a custom button in single product pages and by a linked button to the product on archives pages:
Code goes in function.php file of your active child theme (or theme).
Tested and works.
Add filter priority in hooks
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text',50 );