Best web application development company. Best web designing company. Best e-commerce, designing, development, migration services all over European countries and worldwide.

How to add a “Buy Now” button along with the “Add To Cart” button in Drupal Commerce ?

If you want to add a “Buy Now” button and an “Add To Cart” button to the Drupal eCommerce site, follow the code below.

function custom_module_form_alter(&$form, &$form_state, $form_id) { if (strpos($form_id, 'commerce_cart_add_to_cart_form') !== false) { if (isset($form['product_id']['#value'])) { $product_id = $form['product_id']['#value']; } else { $product_id = $form['product_id']['#default_value']; } $form['buy_now_pid'] = array( '#type' => 'hidden', '#name' => 'buy_now_pid', '#default_value' => $product_id, ); $form['buy_now_submit'] = array( '#type' => 'submit', '#name' => 'buy_now', '#value' => t('Buy Now'), '#submit' => array('custom_module_buy_now_call_back'), '#weight' => '52', '#attributes' => array('class' => array('btn-buy-now')), ); } }
function custom_module_form_alter(&$form, &$form_state, $form_id) {
if (strpos($form_id, 'commerce_cart_add_to_cart_form') !== false) {
if (isset($form['product_id']['#value'])) {
    $product_id = $form['product_id']['#value'];
}
else {
    $product_id = $form['product_id']['#default_value'];
}
$form['buy_now_pid'] = array(
'#type' => 'hidden',
'#name' => 'buy_now_pid',
'#default_value' => $product_id,
);
$form['buy_now_submit'] = array(
'#type' => 'submit',
'#name' => 'buy_now',
'#value' => t('Buy Now'),
'#submit' => array('custom_module_buy_now_call_back'),
'#weight' => '52',
'#attributes' => array('class' => array('btn-buy-now')),
);
}
}
Add Now and Add cart button Drupal ecommerce
Callback function to add product to cart and redirect to checkout. Callback function also handles custom functionalities while adding product to cart.

Sreyas offer the best Drupal development service with our most experienced team, which will greatly satisfy our client all over the world.

Recent Blogs


Posted

in

by

Tags:

Comments

Leave a Reply

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

To Know Us Better

Browse through our work.

Explore The Technology Used

Learn about the cutting-edge technology and techniques we use to create innovative software solutions.