How do I generate an order using the "Add to Cart" button in a custom PHP page? In Drupal Commerce Kickstart, I used custom PHP page in Drupal root folder. As per requirements, I chose custom PHP Code to show products in different logic pattern. I am getting product id value for each product in that page. Now, I need "Add to cart" button which should generate order number and redirect it to checkout page directly.

How do I generate an order using the "Add to Cart" button in a custom PHP page?
Though I prefer the Commerce Add To Cart Filter module to adding a "Add to cart" button anywhere in my content by mentioning the product ID with the suggested method, since you need PHP code, I am copying my old code which I don't use anymore; maybe it can help you. 

function MYMODULE_commerce_menu() {
  $items = array();
  $items['mysite/trial-buy'] = array(
    'title' =&gt; 'Trial Plan',
    'page callback' =&gt; 'MYMODULE_add_single_product',
    'access arguments' =&gt; array('view published content'),
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}

function MYMODULE_add_single_product(){
  global $user;
  $product_id = 59;//This is my product ID, place your's here.
  $order = commerce_order_new($user-&gt;uid, 'checkout_checkout'); 
  commerce_order_save($order);
  $product = commerce_product_load($product_id);
  $line_item = commerce_product_line_item_new($product, 1, $order-&gt;order_id);
  commerce_line_item_save($line_item);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper-&gt;commerce_line_items[] = $line_item;
  commerce_order_save($order);  
  drupal_goto('checkout/' . $order-&gt;order_id);//Forward to checkout. You can have your method here.
}


This is the code I came out with the help of Commerce guys documentation when I was working with some custom need like yours.