I want to add a class only on the add to cart button text for design purpose.
I tried but it doesn’t work :
add_filter( 'woocommerce_product_single_add_to_cart_text', 'add_custom_class_to_add_to_cart_button_text' );
function add_custom_class_to_add_to_cart_button_text() {
$text = ('<span class="custom-class">' . __( 'Add to Cart Button Text', 'woocommerce' ) . '</span>') ;
return $text;
}
Do you know how to target ATC button text only or wrap the text ?
2
Answers
Please try this:
}
If you want to add a class to the "Add to Cart" button text on a single product page in WooCommerce, you can use the following code
snippet
. This code uses a filter to modify the button text and wrap it in a span element with your custom class:Make sure to place this code in your theme’s functions.php file or in a custom plugin. This code will wrap the "Add to Cart" button text in a span element with the class "custom-class," which you can then style using CSS for your design purposes.