Here is how you would customize your WooCommerce default button to display a “Read More” button with price included. This will only apply in a certain category you wish to choose. In some cases you may not want to use the “Add to Cart” button and may need to customize certain categories in your website to allow for a inquiry form type scenario instead of the default “Add to Cart” checkout system.

In this simple function we’ll hook in to the WordPress WooCommerce loop and add a function called change_simple_shop_add_to_cart_btn. Then set a conditional statement to check if it’s a simple product, in a certain category, then change the value and return back.

Change Add to Cart Button by Category WooCommerce

This is a php function that will replace the Add to Cart button with a Read More button to a certain category in WooCommerce (in this case it’s the Firearms category).

In your functions.php


// Replace the Add to Cart Btn in Category Firearms with Read More Btn

  add_filter('woocommerce_loop_add_to_cart_link','change_simple_shop_add_to_cart_btn',10,2);
  function change_simple_shop_add_to_cart_btn( $html, $product ){
      if( $product->is_type('simple')) {

       $category_name = $product->get_categories();
       

      if (strstr($category_name, 'Firearms')) { // your category name 'Firearms'

 $html = sprintf( '%s',
                  esc_url( get_the_permalink() ),
                  esc_attr( $product->get_id() ),
                  esc_html(  __( 'Read More', 'woocommerce' ) )
          );
          $category_name = $product->get_categories();
      }
    }
      return $html;
  
      } 
example Read More button

This adds a “Read More” button to your Shop Page

To add another category copy the function in full and only change your category “name”.

In your Single Product Page you will need to hide the “Add to Cart” button (using CSS) or create a new template file for the category.  Then you would  add your “Inquiry Form”.

NEXT, LEARN HOW TO CREATE A CUSTOM SINGLE-PRODUCT-TEMPLATE FOR WORDPRESS

We’ll continue to remove the Add to Cart button in the single product page of our targeted category and add in the inquiry form.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get a free proposal for your business