I am working with E-Commerce module of Drupal 7. I want to redirect Add to Cart button link to product page only those products which have attribute otherwise I want to add product direct to cart.
3 Answers
Using Drupal Rules Module:
To redirect directly to checkout after a user clicks 'add to cart'
- Admin -> Configure -> Rules -> Add New Rule
- Give it a title of 'Add to Cart - Redirect to Checkout'
- Set React on event to: After adding a product to the cart
- Add new Action - set this to 'Page redirect'
- Give it a value of 'checkout' and save.
Now when users click your add to cart button, they will be taken directly to checkout. Alternatively, you can send them to /cart by change the value in step 5.
-
Hi TreyeDesigns and welcome. Though it might be possible to use these methods to solve the problem, could you include what the user would need to do to achieve the desired functionality? (What hook and which rules would help here?) Sep 29, 2017 at 9:12
-
2
You need to add view php options in your listing page and then you can get your attributes in that php field, you put the conditions and make the link as you want
Add a hook form alter that changes the add to cart form to add another #submit callback. In this callback, add your logic to check attributes, if you need to redirect, set $form_state['redirect']
See https://drupal.stackexchange.com/a/128001/42761 for more on how to alter the form