Change Default "Add to Cart" Button Text to "Pre-order Now" in WooCommerce
Blog
Posted by Nuno Marques on 23 Nov 2020
Steps to Implement
To change the default "Add to Cart" button text to "Pre-order Now" in WooCommerce, follow these steps:
- Open your
functions.phpfile in your child theme directory. - Add the following code snippet to the file:
/* Change default "Add to Cart" button text to "Pre-order Now" */
add_filter( 'woocommerce_product_add_to_cart_text', 'change_add_to_cart_to_pre_order', 20, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_add_to_cart_to_pre_order', 20, 2 );
function change_add_to_cart_to_pre_order( $button_text, $product ) {
// Define your specific product IDs in this array
$specific_ids = array(2413, 2414, 2415);
if( in_array($product->get_id(), $specific_ids) ) {
$button_text = __('Pre-order now', 'woocommerce');
} else {
$button_text = __('Add to cart', 'woocommerce');
}
return $button_text;
}
- Replace the
$specific_idsvariable with the IDs of your desired products. In this example, we use product IDs2413,2414,2415.
Note
Ensure that you have proper backups and testing in place before making changes to your theme files.