Support » Plugin: WooCommerce » Can't Change Add to Cart text for one specific product id.

  • Resolved Ike Ten

    (@ike-ten)


    Hello- Anyone know how to change ‘add to car’t button text on single product page based on specific product id?

    For example change ‘add to cart’ text to ‘complete membership’ for a product called membership with product id of ‘ID: 990’.

    This is useful for woo shops selling product and at the same time offering different services for example memberships. This will make the add to cart text more descriptive of the product as a Call to Action button.

    I have been successful in changing the text based on product type by referring to this doc page on docs.woothemes.com.

    I have combed through the internet, for the past few days to find something close to an answer yet it seems this issue is not a popular one.

    Many Thanks,
    Isaac

    https://wordpress.org/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • HI @mikejolley,

    Decided to add this detail after your post on the support forum.

    1. Am on a local install of wordpress on my pc using mamp.

    2. Am not using any premium plugins. From woothemes now although I will later in the website de stage.

    3. My wprdpress install is so bare bones – Twenty sixteen theme and woocoomerce version 2.5.4. I will post my system status report here soon too.

    Many thanks.

    System Report.

    Home URL: http://localhost/thesite
    Site URL: http://localhost/thesite
    WC Version: 2.5.0
    Log Directory Writable: ✔ C:\MAMP\htdocs\thesite/wp-content/uploads/wc-logs/
    WP Version: 4.4.2
    WP Multisite: –
    WP Memory Limit: 256 MB
    WP Debug Mode: –
    Language: en_US
    Server Environment
    Server Info: Apache/2.2.27 (Win32) DAV/2 mod_ssl/2.2.27 OpenSSL/1.0.1g mod_fcgid/2.3.9 mod_wsgi/3.4 Python/2.7.6 PHP/5.6.8 mod_perl/2.0.8 Perl/v5.16.3
    PHP Version: 5.6.8
    PHP Post Max Size: 8 MB
    PHP Time Limit: 30
    PHP Max Input Vars: 1000
    SUHOSIN Installed: –
    MySQL Version: 5.5.41
    Max Upload Size: 2 MB
    Default Timezone is UTC: ✔

    Thats it,

    Thanks.

    Plugin Author Mike Jolley

    (@mikejolley)

    Adapt:

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); 
    
    function woo_custom_cart_button_text() {
            return __( 'My Button Text', 'woocommerce' );
    
    }

    To check the product, like so:

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); 
    
    function woo_custom_cart_button_text( $text ) {
    global $product;
    
    if ( 123 === $product->id ) {
       $text = 'Product 123 text';
    }
    return $text;
    }

    Thanks @mikejolley,

    It worked beautifully. You solved a major issue that is necessary to complete my project.
    I can now go through to install themes and other plugins, then move my site from local install to live.
    Am still very new to WordPress and learning fast.

    Best Regards,
    Isaac.

    Thanks @mikejolley. Really appreciate the help.

    Is there a way to show multiple custom Add to Cart texts with this? I tried the code below but not having any luck:

    add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' );  // CHANGES INLINE BUY BTN BANNER
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // CHANGES SINGLE PRODUCT PAGE BUY BTN
    
    function woo_custom_cart_button_text( $text ) {
    global $product;
    
    if ( 4471 === $product->id ) { //WONDER KINDRED TRIBE
       $text = 'Join the Kindred';
    } elseif ( 4297 === $product->id ) { //SOUND JOURNEY
       $text = 'Toss in your tipi';
    }
    return $text;
    }

    Default setup is working great on our end. Cheers!

    • This reply was modified 3 years, 2 months ago by TigreTwoTwoTwo. Reason: added question
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can't Change Add to Cart text for one specific product id.’ is closed to new replies.