修改WooCommerce结账默认"Save to account"文本的最优方案(Stripe场景)
Great question — using a full translation plugin just to tweak one line of text is total overkill, and I totally get why you'd want a cleaner solution. Here are a few targeted, lightweight approaches to update that checkbox label without extra bloat:
WooCommerce provides a dedicated filter hook for modifying that exact checkbox label, which is the most update-safe way to make the change. This method won't break when you update WooCommerce or the Stripe plugin, as long as the core hook remains intact (which it's designed to do).
Add this code snippet to your child theme's functions.php file, or a custom utility plugin (always prefer a child theme over modifying the parent theme directly):
add_filter( 'woocommerce_save_payment_method_checkbox_label', 'custom_stripe_save_payment_label' ); function custom_stripe_save_payment_label( $original_label ) { // Only change the label if the current payment gateway is Stripe $current_gateway = WC()->payment_gateways()->get_current_gateway(); if ( $current_gateway && $current_gateway->id === 'stripe' ) { return 'Save my credit card details for future purchases (optional)'; } // Keep the original label for other payment methods return $original_label; }
This checks if the active gateway is Stripe before swapping the label, so you don't accidentally alter text for other payment gateways.
If for some reason the first hook doesn't work (unlikely, but possible if you're using an older Stripe plugin version), you can use WordPress's core gettext filter to target the exact string. This works for any translatable text in WordPress or WooCommerce:
add_filter( 'gettext', 'custom_translate_save_payment_label', 20, 3 ); function custom_translate_save_payment_label( $translated_text, $original_text, $domain ) { // Target the exact string and WooCommerce's text domain if ( $original_text === 'Save to account' && $domain === 'woocommerce' ) { // Ensure we're on the checkout page and using Stripe if ( is_checkout() ) { $current_gateway = WC()->payment_gateways()->get_current_gateway(); if ( $current_gateway && $current_gateway->id === 'stripe' ) { $translated_text = 'Save my credit card details for future purchases (optional)'; } } } return $translated_text; }
The 20 priority ensures this runs after any default translations, so your custom text takes precedence.
If you prefer working with template files, you can override the Stripe payment template in your child theme. Just note that this requires you to check for plugin updates — if Stripe changes their template file, you'll need to update your overridden version to match any new features or fixes.
Here's how to do it:
- Locate the Stripe template file: Typically found at
wp-content/plugins/woocommerce-gateway-stripe/templates/payment-methods/stripe.php - Copy this file to your child theme directory at
woocommerce/payment-methods/stripe.php(create the folders if they don't exist) - Open the copied file, find the line with "Save to account", and replace it with your custom text.
Between these options, the filter hook method is hands down the best choice — it's lightweight, update-safe, and doesn't require managing template files.
内容的提问来源于stack exchange,提问作者warm__tape

