I used the following code to implement "add to cart" in my tpl.php file, and it works fine:
$product=commerce_product_load($node->field_product['und'][0]['product_id']);
$line_item = commerce_product_line_item_new($product,1);
$line_item->data['context']['product_ids'] = array($product->product_id);
$show_quantity = TRUE;
$form = drupal_get_form('commerce_cart_add_to_cart_form', $line_item,$show_quantity);
print render($form);
Right now, it can only use its original price. However, I want to add this product with a special price to the cart and use this special price to checkout.
I have already created a "Price" field named "field_special_price", and if I use print_r($product)
, I can see its value and can use the value by $product->field_special_price['und'][0]['amount']