我正在構建一個 WordPress 網站,并且我已經在那里集成了 PayPal 結賬功能。現在,我想在結帳頁面添加折扣優惠券代碼。如何通過在下面的代碼中進行一些修改來實作這一點?
<meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Ensures optimal rendering on mobile devices -->
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Optimal Internet Explorer compatibility -->
<!-- Include the PayPal JavaScript SDK; replace "test" with your own sandbox Business account app client ID -->
<script src="https://www.paypal.com/sdk/js?client-id=<test-id>;currency=USD"></script>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '77.44' // Can reference variables or functions. Example: `value: document.getElementById('...').value`
}
}]
});
},
// Finalize the transaction after payer approval
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction ' transaction.status ': ' transaction.id '\n\nSee console for all available details');
// When ready to go live, remove the alert and show a success message within this page. For example:
// var element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
uj5u.com熱心網友回復:
如果您使用的是 Wordpress,您可能需要考慮某種以某種方式與 Wordpress CMS 實際集成的結帳型別——例如像 WooCommerce 這樣的插件,以及它的各種 PayPal 付款方式插件之一。
否則,如果使用上述獨立的 HTML/JS 代碼,則不會以任何方式與 Wordpress 互動。它只是做你告訴它做的事情。在此示例中指定金額 77.44 的情況下,您可以添加自己的代碼以應用折扣。您可以自由地使用 HTML/JS 做任何可能的事情,如果這對您來說是新的,那么有許多指南可以幫助您開始編程。
uj5u.com熱心網友回復:
要創建折扣按鈕代碼: 1.) 登錄到您的 PayPal 帳戶。
2.) 單擊工具。
3.) 單擊 PayPal 按鈕。
4.) 單擊首選按鈕型別的選擇按鈕。
5.) 輸入您的資訊以根據您的需要自定義按鈕。
6.) 單擊步驟 2:跟蹤庫存、損益并取消選中 PayPal 上的保存按鈕。(這可確保您創建的是非托管按鈕。)
7.) 單擊創建按鈕。
8.) 單擊洗掉代碼保護。(您必須這樣做才能使您的代碼可編輯。) 9.) 單擊“選擇代碼”以選擇按鈕代碼。
10.) 將按鈕代碼復制并粘貼到您自己的網頁代碼中。
用于應用 10% 折扣代碼的 JavaScript 代碼示例
<script type="text/javascript">
<!--
discnt = 10; // set blanket 10% discount
//-->
</script>
這是應用 10% 折扣代碼的按鈕的代碼
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal';
discnt = 10;
coupval = '(blanket)';
ReadForm (this);
discnt = 0;">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="your_email_goes_here@your_site.com" />
<input type="hidden" name="item_name" value="Test Item" />
<input type="hidden" name="amount" value="10.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="baseamt" value="10.00" />
Input quantity >
<input type = "text"
name = "quantity"
value = "1"
size = "3" />
<input type="image" src="addcart.gif" name="submit" alt="cart add" />
</form>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/348870.html
