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' => 'Trial Plan',
'page callback' => 'MYMODULE_add_single_product',
'access arguments' => array('view published content'),
'access callback' => TRUE,
'type' => 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->uid, 'checkout_checkout');
commerce_order_save($order);
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, 1, $order->order_id);
commerce_line_item_save($line_item);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
commerce_order_save($order);
drupal_goto('checkout/' . $order->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.