1

I am using a Woocommerce website with Divi theme. I am displaying Featured Products with the help of shop module in Divi theme. Currently Divi shop module doesn't display the add to cart button. So I added a hook for implementing the same.

Link: https://intercom.help/elegantthemes/faq-s-and-troubleshooting/how-to-add-add-to-cart-button-in-divi-shop-pages

But the problem is that the Add To Cart button is ajax type. I need the button to be redirected to corresponding product page. Also if the woocommerce product price is zero, remove add to cart and instead show Contact Us Button.

I tried the following solutions, but couldnt be able to satisfy with my requirements.

Hide "Add to cart" button when the product price is zero When price is 0 change add to cart button to "request quote"

I need to implement the feature like this: https://i.stack.imgur.com/Uo2aW.jpg

Vishnu
  • 704
  • 12
  • 34

1 Answers1

1

Put this in your theme functions.php file. Thanks!

function replace_add_to_cart() {
   global $product;

   if( $product->get_price() == 0 ) {
     $link = 'YOUR CONTACT PAGE URL';
     $button_text = 'Contact Us';
   } else {
     $link = $product->get_permalink();
     $button_text = 'Buy Now';
   }

   echo do_shortcode('[button link="' . esc_attr($link) . '"]'.$button_text.'[/button]');
}
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');