フォームのデータを処理した後、PayPal にリダイレクトする非常に簡単な方法があります。したがって、このエントリの原則のみに従う必要があります。
まず、プラグインのコードから WordPress init にアクションを設定しました。
add_action( 'init', 'my_init');
ここで、'my_init' 関数を実装します。
if( !function_exists( 'my_init' ) ){ // Use function_exists to avoid conflicts
function my_init(){
if( $_POST[ 'unique_variable' ]){ // A form field to identify we are processing the form
//...process here your form
// and then print the form to be redirected to PayPal
?>
<form action="https://www.paypal.com/cgi-bin/webscr" name="myform" method="post">
<input type="hidden" name="business" value="seller@email.com" />
<input type="hidden" name="item_name" value="Product Name" />
<input type="hidden" name="item_number" value="Product Number" />
<input type="hidden" name="amount" value="10" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="lc" value="EN" />
<input type="hidden" name="return" value="URL to the product after check the payment" />
<input type="hidden" name="cancel_return" value="URL to use if user cancel the payment process" />
<input type="hidden" name="notify_url" value="URL of IPN in your website to check the payment" />
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="page_style" value="Primary" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input type="hidden" name="ipn_test" value="1" />
</form>
<script type="text/javascript">document.myform.submit();</script>
<?php
exit; // It is very important stop the WordPress in this point
}
}
}
PayPal フォーム フィールドの値を、電子メール、IPN への URL、キャンセルおよび返品ページ、製品の名前、番号、および請求金額で変更する必要があります。
PayPal フォームを印刷した後の "exit" 文に注意してください。PHP の実行、document.myform.submit(); を停止する必要があります。読み込まれた後に PayPal フォームを送信します。
このテーマの優れた出発点は、プレミアム バージョンのプラグイン計算フィールド フォーム ( http://wordpress.org/plugins/calculated-fields-form/ )です。
;-) エリコ