Hello Everyone, today I will guide you "to change add to cart text on product page by its type?"
If you want to change the add to cart text according to product type, the first thing is you have to get the product type. In the below code $product is a global variable, $pType store the product name.
and the last there are four case which I have define in the below code and they are- external, grouped, variable and
last one is default case read more.
Add the below code to your functions.php file.
<?php
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$pType = $product->product_type;
switch ( $pType ) {
case 'external':
return __( 'Buy product', 'woocommerce' );
break;
case 'grouped':
return __( 'View products', 'woocommerce' );
break;
case 'simple':
return __( 'Add to cart', 'woocommerce' );
break;
case 'variable':
return __( 'Select options', 'woocommerce' );
break;
default:
return __( 'Read more', 'woocommerce' );
}
}
?>
0 Comment(s)