06
MARCH
ウェブTUESDAY 2018 / 3 / 6
Welcartで注文完了画面に注文番号を表示させる方法
Text by Hiroyuki Matsumoto
WordPressの通販プラグイン「Welcart」にて、下記のような注文完了画面を作成することになりました。
注文番号/受注日時/お客さまメールアドレスを表示するという仕様です。
今回はこちらをどのように挿入するかを備忘録がてら残しておきます。
1.編集対象ファイル
Welcart の注文完了画面は、テーマフォルダ内の
wc_templates/cart/wc_completion_page.php
を使います。
※ファイルがない場合は、Welcartプラグインをインストール時に自動的に入る Welcart Basicテーマ内の同ファイルが使われます。
カスタマイズするので、Welcart Basicテーマからコピーして自分のテーマに入れておきましょう。
2. 情報が入っている変数
wc_completion_page.php 内では下記2つの変数が利用できます。
$usces_entries : 購入者の情報/配送先情報/注文情報などの詳細情報が入っています。
$usces_carts : 購入者の購入した商品情報が入っています。
(データ例は文末に掲載しています)
3. データの参照
それぞれ下記に入っています。
注文番号 : $usces_entries[‘order’][‘ID’]
受注日時 : 無いため、プログラムの実行日時で代用
購入者メールアドレス : $usces_entries[‘customer’][‘mailaddress1’]
これらを wc_completion_page.php 内にて利用すればOKです。
※上記をコピペすると ‘ が全角になっているため注意
利用する際は esc_html関数等を用いてエスケープ処理することも忘れないで下さいね。
4. 時刻がきちんと表示されない罠
受注日時は <?php echo date(“Y/m/d H:i”); ?> で表示させればいいやー!と思っていたのですが、どうも Welcart内部でなんかいじっているのか、正常に動作しません。世界標準時(日本との時差9時間)で出力されてしまいます。
以前ためしに functions.php に
<?php date_default_timezone_set(‘Asia/Tokyo’); ?>
と入れてみたところ、日付は正常に表示されるようになりましたが、
Welcart + SonyPaymentの組み合わせでクレジットカード処理が正常にできなくなる重篤な問題に見舞われました。(24分の9の確率で成功するからタチが悪い)
date関数の代わりに、WordPress関数である date_i18n関数を用いることで回避できます。
本文は以上です。
なお現在制作中のこのサイトですが、4月公開予定です。
また公開次第持田あたりからアナウンスがあると思います!
おまけ. 各変数の var_dump実行結果
$usces_carts
array(2) { [0]=> array(7) { ["serial"]=> string(38) "a:1:{i:495;a:1:{s:9:"testitem4";i:0;}}" ["post_id"]=> int(495) ["sku"]=> string(9) "testitem4" ["options"]=> array(0) { } ["price"]=> string(4) "2800" ["quantity"]=> int(1) ["advance"]=> string(0) "" } [1]=> array(7) { ["serial"]=> string(38) "a:1:{i:111;a:1:{s:9:"testitem1";i:0;}}" ["post_id"]=> int(111) ["sku"]=> string(9) "testitem1" ["options"]=> array(0) { } ["price"]=> string(4) "1200" ["quantity"]=> int(1) ["advance"]=> string(0) "" } }
商品の投稿ID(post_id)がと商品のSKUが取得できますので、それ経由で大抵のデータは引っ張ってこれそうですね。
$usces_entries
array(8) { ["customer"]=> array(23) { ["mailaddress1"]=> string(17) "temp@magicword.jp" ["mailaddress2"]=> string(17) "temp@magicword.jp" ["password1"]=> string(0) "" ["password2"]=> string(0) "" ["name1"]=> string(9) "テスト" ["name2"]=> string(6) "太郎" ["name3"]=> string(9) "テスト" ["name4"]=> string(9) "タロウ" ["zipcode"]=> string(7) "6830001" ["address1"]=> string(21) "米子市皆生温泉" ["address2"]=> string(6) "1-2-38" ["address3"]=> string(16) "OUランド58階" ["tel"]=> string(12) "0120-444-444" ["fax"]=> string(0) "" ["country"]=> string(2) "JP" ["pref"]=> string(9) "鳥取県" ["ID"]=> string(4) "1000" ["point"]=> string(1) "0" ["delivery_flag"]=> string(1) "0" ["delivery"]=> string(0) "" ["registered"]=> string(19) "2018-02-28 12:48:20" ["nicename"]=> string(0) "" ["status"]=> string(1) "0" } ["delivery"]=> array(21) { ["name1"]=> string(9) "テスト" ["name2"]=> string(6) "太郎" ["name3"]=> string(9) "テスト" ["name4"]=> string(9) "タロウ" ["zipcode"]=> string(7) "6830001" ["address1"]=> string(21) "米子市皆生温泉" ["address2"]=> string(6) "1-2-38" ["address3"]=> string(16) "OUランド58階" ["tel"]=> string(12) "0120-444-444" ["fax"]=> string(0) "" ["country"]=> string(2) "JP" ["pref"]=> string(9) "鳥取県" ["delivery_flag"]=> string(1) "0" ["mailaddress1"]=> string(17) "temp@magicword.jp" ["mailaddress2"]=> string(17) "temp@magicword.jp" ["ID"]=> string(4) "1000" ["point"]=> string(1) "0" ["delivery"]=> string(0) "" ["registered"]=> string(19) "2018-02-28 12:48:20" ["nicename"]=> string(0) "" ["status"]=> string(1) "0" } ["order"]=> array(17) { ["usedpoint"]=> string(0) "" ["total_items_price"]=> int(4000) ["discount"]=> float(0) ["shipping_charge"]=> float(0) ["cod_fee"]=> int(0) ["payment_name"]=> string(9) "代引き" ["delivery_method"]=> string(1) "0" ["delivery_date"]=> string(21) "指定できません" ["delivery_time"]=> string(10) "9:00-12:00" ["total_full_price"]=> float(4000) ["note"]=> string(0) "" ["tax"]=> int(0) ["delidue_date"]=> string(0) "" ["cus_id"]=> string(0) "" ["total_price"]=> float(4000) ["getpoint"]=> int(0) ["ID"]=> int(1001) } ["reserve"]=> array(1) { ["pre_order_id"]=> string(13) "5a9d0435499e1" } ["condition"]=> array(12) { ["display_mode"]=> string(9) "Usualsale" ["campaign_privilege"]=> string(0) "" ["campaign_category"]=> string(1) "2" ["privilege_point"]=> int(0) ["privilege_discount"]=> int(0) ["tax_display"]=> string(8) "activate" ["tax_mode"]=> string(7) "include" ["tax_target"]=> string(3) "all" ["tax_rate"]=> int(0) ["tax_method"]=> string(7) "cutting" ["membersystem_state"]=> string(8) "activate" ["membersystem_point"]=> string(10) "deactivate" } ["custom_order"]=> array(4) { ["gift_type"]=> string(6) "なし" ["gift_naigai"]=> string(6) "なし" ["gift_fukuro"]=> string(6) "なし" ["gift_sender"]=> string(0) "" } ["custom_customer"]=> NULL ["custom_delivery"]=> NULL }
TEXT by
松本 博之(まつもとひろゆき)
1978年、鳥取県米子市生まれ。
株式会社マジックワード WEBシステムの開発・運用を担当。
WordPressの実績多数。表面的な使用方法を把握するだけでなく、WordPressのソースコードを読み解いて対応できます。
国家資格の基本情報処理技術者を保持。