Filter uncanny-learndash-groups

woocommerce_product_add_to_cart_text

Filters the text displayed on the add to cart button for products.

add_filter( 'woocommerce_product_add_to_cart_text', $callback, 10, 1 );

Description

Filters the text displayed on the "Add to cart" button for products. Developers can modify this text, for instance, to show "Read More" for unpurchasable items or to customize button labels across their site. This filter fires just before the button text is output.


Usage

add_filter( 'woocommerce_product_add_to_cart_text', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

// Change the "Add to cart" button text for products that are on sale.
add_filter( 'woocommerce_product_add_to_cart_text', 'my_custom_add_to_cart_text', 10, 2 );

function my_custom_add_to_cart_text( $text, $product ) {
    // Check if the product is on sale.
    if ( $product->is_on_sale() ) {
        // If it's on sale, change the text to "Buy Now!".
        $text = esc_html__( 'Buy Now!', 'my-text-domain' );
    }
    // Return the modified or original text.
    return $text;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/includes/woocommerce/wc_product_courses.php:39
src/includes/woocommerce/wc_product_group.php:38
src/includes/woocommerce/wc_product_license.php:40

public function add_to_cart_text() {
		$text = __( 'Add to cart', 'woocommerce' );

		return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
	}


Scroll to Top