• Resolved Denis

    (@brawick)


    Hello, Sorry for missposting (possible), But I realy have no idea how to do this.
    how to change text on cart button for some brand?
    like:

    if($product->brand == 'stihl'){
    $text->cartButton = 'reserve';
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Denis

    (@brawick)

    Where am i wrong?

    add_filter( 'woocommerce_product_add_to_cart_text', 'change_addtocart_text_for_stihl' );
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_addtocart_text_for_stihl' );  
      
    function change_addtocart_text_for_stihl($brands) {
    	if ( $brand === 'stihl' ) {
        return __( 'Reserve', 'woocommerce' );
    	}
    	else {
    		return __( 'To Cart', 'woocommerce' );
    	}
    }
    • This reply was modified 4 years, 11 months ago by Denis.
    Thread Starter Denis

    (@brawick)

    add_filter( 'woocommerce_product_add_to_cart_text', 'change_addtocart_text_for_stihl' );
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_addtocart_text_for_stihl' );   
    function change_addtocart_text_for_stihl() {
    global $product;
       $product_id = $product->get_id();
       $brands = wp_get_post_terms( $product_id, 'pwb-brand' );
       foreach( $brands as $brand )
    	if ($brand->name === 'STIHL' ) {
        return __( 'В резерв', 'woocommerce' );
    	}
    	else {
    		return __( 'Купить', 'woocommerce' );
    	}
    }

    Done

    Plugin Contributor titodevera

    (@titodevera)

    Solved ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to change addtocart button at some brand?’ is closed to new replies.