今天要在自訂的php頁面呼叫wc的api記錄,因為老闆說要另外做一頁就這樣搞了XD不要問
載入WP的函式庫
require_once(dirname(dirname(__FILE__)).'/wp-load.php');
取得指定產品id的清單,並且支援i18n
/*
簡: zh-hans
繁: zh-hant
*/
if(isset($_GET['lang'])){
$currentLang = $_GET['lang'];
}else{
$currentLang = 'en';
}
$_pf = new WC_Product_Factory();
foreach ($related_product_ids as $id) {
$translate_post_id = icl_object_id($id, 'product', FALSE,$currentLang);
$_product = $_pf->get_product($translate_post_id);
// echo $id;
// echo ($_product->get_image());
var_dump($_product);
}
模擬paypal post動作
執行payal的按鈕後就會產生一筆訂單到用戶資料了,看post是打checkout的api (checkout/?wc-ajax=checkout)
追了一下相關要看的source code如下
- WC_Gateway_Paypal ( includes/class-wc-gateway-paypal.php)
其呼叫process_payment方法後會產生paypal 結帳頁面url
- WC_Gateway_Paypal_Request (includes/class-wc-gateway-paypal-request.php)
呼叫 get_request_url會產生paypal結帳url
最後找到一個不錯外掛(https://wp-ecommerce.net/paypal-pro-payment-gateway-for-woocommerce)範例比較符合需求
如要自已幹api可參考,目前也決定自幹API
https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/
參考
- https://cloudwp.pro/blog/woocommerce-%E8%87%AA%E8%A8%82%E6%94%B6%E4%BB%B6%E6%AC%84%E4%BD%8D/
- http://www.solagirl.net/woocommerce-test-payment-gateway.html
- https://www.paypal.com/tw/cgi-bin/webscr?cmd=_pdn_howto_checkout_outside
- https://www.paypalobjects.com/webstatic/lvm/tw/zh/using-paypal/integration-guide.pdf
- https://wp-ecommerce.net/paypal-pro-payment-gateway-for-woocommerce (有達到我們需要的套件)
- http://www.solagirl.net/woocommerce-paypal-rmb.html
沒有留言:
張貼留言
留個話吧:)