Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change add to cart text on product page by its type?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    Hello Everyone, today I will guide you "to change add to cart text on product page by its type?"

    If you want to change the add to cart text according to product type, the first thing is you have to get the product type. In the below code $product is a global variable, $pType store the product name.
    and the last there are four case which I have define in the below code and they are- external, grouped, variable and last one is default case read more.

    Add the below code to your functions.php file.

    <?php
    add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
    
    function custom_woocommerce_product_add_to_cart_text() {
        global $product;
    
        $pType = $product->product_type;
    
        switch ( $pType ) {
            case 'external':
                return __( 'Buy product', 'woocommerce' );
            break;
            case 'grouped':
                return __( 'View products', 'woocommerce' );
            break;
            case 'simple':
                return __( 'Add to cart', 'woocommerce' );
            break;
            case 'variable':
                return __( 'Select options', 'woocommerce' );
            break;
            default:
                return __( 'Read more', 'woocommerce' );
        }
    
    }
    
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: