Drupal custom coding checkout redirect not working I have used custom coding to add a product into a cart.

 $items['buynow/%'] = array(
    'title' => t('buynow'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('custom_module_my_form3',1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
function custom_module_my_form3($form, &amp;$form_state,$id) {
global $user;
$product_id=$id;
$product = commerce_product_load($product_id);
$quantity=1;
$line_item = commerce_product_line_item_new($product, $quantity);
$line_item_added = commerce_cart_product_add($user->uid, $line_item);
$order_id=$line_item_added->order_id;
drupal_goto('checkout/'.$order_id);
}


Product added succesfully in the cart but redirecting into checkout page doesn't work.It redirecting into home page.

I have created link for each product like buynow/product_id. I have also created a custom menu path like buynow/%.

After that put the above code in the callback by passing argument.
Your fault is want using drupal_goto in form builder!!!

Change your code to this 

 $items['buynow/%'] = array(
    'title' =&gt; t('buynow'),
    'page callback' =&gt; 'custom_module_my_form3',
    'page arguments' =&gt; array(1),
    'access arguments' =&gt; array('access content'),
    'type' =&gt; MENU_CALLBACK,
  );

function custom_module_my_form3() {
   global $user;
   $id=arg(1);
   $product_id=$id;
   $product = commerce_product_load($product_id);
   $quantity=1;
   $line_item = commerce_product_line_item_new($product, $quantity);
   $line_item_added = commerce_cart_product_add($user-&gt;uid, $line_item);
   $order_id=$line_item_added-&gt;order_id;
   drupal_goto('checkout/'.$order_id);
}