Jifinner
Jifinner

Reputation: 33

Change text on order button for WooCommerce subscriptions

The issue described here is exactly what I need to do and the solution works:
Woocommerce: Change text on order button [Updated]

However, we accept one time "orders" in the form of donations and subscriptions to sponsor a child. If there is a subscription in the cart, the checkout button reads "Sign up now". I need it to read "Give Now" no matter what is in the cart.

http://www.childhopeonline.org (the changes described above are not live and it currently uses the default "Place order" which is consistent no matter what is in the cart)

Translation doesn't seem to work.

I've also tried:

function woocommerce_custom_subscription_product_single_add_to_cart_text( $text = '' , $post = '' ) {

    global $product;

    if ( $product->is_type( 'subscription' ) ) {
        $text = get_option( WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text', __( 'Give Now', 'woocommerce-subscriptions' ) );
    } else {
        $text = $product->add_to_cart_text(); // translated "Read More"
    }

    return $text;
}
add_filter('woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_subscription_product_single_add_to_cart_text', 2, 10);

Upvotes: 3

Views: 4862

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

To change the text of the submit button in the checkout page the correct filter hook to use is woocommerce_order_button_text. Here is that code:

add_filter('woocommerce_order_button_text', 'subscriptions_custom_checkout_submit_button_text' );
function subscriptions_custom_checkout_submit_button_text( $order_button_text ) {
    if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
        $order_button_text =  __( 'Give Now', 'woocommerce-subscriptions'  );
    } else {
        // You can change it here for other products types in cart
        # $order_button_text =  __( 'Something here', 'woocommerce-subscriptions'  );
    }
    return $order_button_text;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested on woocommerce 3.1+ and works.

Or you can change it in WooCommerce > Settings > Subscriptions (tab):

enter image description here

Upvotes: 5

Related Questions