Archived topic
Add to cart button text edit
3 replies · Started by Azari on July 10, 2021
Hi,
I couldn't find a way to change the add to the cart button text.
Instead of "add to cart" I have the "Select option" text.
Please see link below:
https://snipboard.io/el6gTr.jpg
Thanks
Hi there,
that means the product is a variable product and an option has to be selected before it can be added to the cart.
Hi,
It can be edited in woocommerce/includes/class-wc-product-variable.php file.
But if edit that way every update for the plugin you need to fix it again.
Hi there,
That particular file is from WooCommerce.
I believe it's this one you're pertaining to? https://woocommerce.github.io/code-reference/files/woocommerce-includes-class-wc-product-variable.html#source-view.60
"Select option" is wrapped in a filter. We can use that.
Example:
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
global $product;
if ( $product->is_type( 'variable' ) ) {
$text = $product->is_purchasable() ? __( 'Custom options text', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
}
return $text;
}, 10 );