How do you customize the default “Add to cart” text on single product page? You can easily do it without editing the core file.
There have a filter “woocommerce_product_single_add_to_cart_text” for single product’s add to cart text.
Change The Add to cart Text
1 2 3 4 5 6 |
add_action( 'woocommerce_product_single_add_to_cart_text', 'paulc_change_single_add_to_cart_text' ); function paulc_change_single_add_to_cart_text( $text ) { $new_text =__('Add to basket', 'woocommerce' ); return $new_text; } |
Adds Price Value in Add to cart Button
1 2 3 4 5 6 7 |
add_action( 'woocommerce_product_single_add_to_cart_text', 'paulc_change_single_add_to_cart_text', 10, 2 ); function paulc_change_single_add_to_cart_text( $text, $product ) { $price = get_woocommerce_currency_symbol( get_woocommerce_currency() ) . wc_get_price_to_display( $product ); $new_text = $text . __(' for ', 'woocommerce' ) . $price; return $new_text; } |
Where are you add the PHP snippet?
You will add the PHP snippet in your theme’s functions.php file or your custom plugin’s PHP file
Leave a Reply