0
votes

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://imgur.com/a/GaQAgUg

1
What difficulty are you facing now? Any errors?Sudharshan Nair
@SudharshanNair : Actually not errors, please see the link imgur.com/a/qK0iKAX I have implemented this much. What i need is this imgur.com/a/GaQAgUgVishnu

1 Answers

1
votes

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');