add_filter( \'woocommerce_product_single_add_to_cart_text\', \'wpse_woo_custom_cart_button_text\' );
add_filter( \'woocommerce_product_add_to_cart_text\', \'wpse_woo_custom_cart_button_text\' );
function wpse_woo_custom_cart_button_text() {
global $product;
$product_type = $product->get_type();
// To modify on a single product page
if( $product_type == \'variable-subscription\' || $product_type == \'variable\' ){
if( is_single() )
return __( \'Buy Now\', \'my-textdomain\' );
else
return __( \'Choose options\', \'my-textdomain\' );
}
// To modify on the shop page
else{
switch ( $product_type ) {
case \'external\':
return __( \'Buy Now\', \'my-textdomain\' );
break;
case \'grouped\':
return __( \'View products\', \'my-textdomain\' );
break;
case \'simple\':
return __( \'Buy Now\', \'my-textdomain\' );
break;
// here\'s your use case
case \'variable\':
return __( \'Select Value\', \'my-textdomain\' );
break;
// Not a default product type
case \'booking\':
return __( \'Book Now\', \'my-textdomain\' );
break;
default:
return __( \'Learn more\', \'my-textdomain\' );
}
}
}
您可以将其放入您的函数中。php文件