• Resolved mondueo

    (@mondueo)


    I need some help creating add to cart buttons on our store page. Currently we are using this code to have the add to cart buttons on the main products page.

    add_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 20 );

    But the add to cart buttons have two different outcomes for the end user. Which i think might be confusing for the user. If it’s a simple product when clicked, the item gets added to the cart for checkout. If it’s a variation product then the user gets taken to the Product page to select the variation. My question is, is there a way to change the text for the variation products “Add to cart” buttons to something like “Select Option” and keep the simple products as “Add to cart”?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support ricardometring

    (@ricardoa8c)

    Hi there,

    Thanks for contacting WooCommerce support.

    To clarify, what type of customization are you trying to accomplish?

    It looks like you wanted the text to be the same as the default text. If you’re trying to customize the appearance of the buttons. I’d suggest using CSS.

    If you’d like to change the button text, I’d suggest using a different filter. This way you can check the product type before displaying a different text:

    add_filter( 'woocommerce_product_add_to_cart_text', 'change_add_to_cart_text', 10, 1 );
    
    function change_add_to_cart_text( $default ) {
    	global $product;
    	$product_type = $product->get_type();
    	if ( 'simple' === $product_type ) {
    		$default = 'Add to cart';
    	} else if ( 'variable' === $product_type ) {
    		$default = 'Select options';
    	}
    
    	return $default;
    }
    Thread Starter mondueo

    (@mondueo)

    Hi thanks for the reply!

    We sell some items by weight and some items by each. So having the add to cart for all items was a little confusing. This is exactly what i was looking for. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘“Add to cart” different versions’ is closed to new replies.