質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

解決済

2回答

6857閲覧

welcartでのカスタムオーダーフィールドの必須が効かない。

margin

総合スコア16

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

0グッド

0クリップ

投稿2016/11/16 08:56

編集2016/11/16 09:17

現在ローカル環境でwordpressのプラグインのwelcartでECサイト構築を勉強しています。

ここで聞くのは場違いかもしれませんが、知恵を貸してほしく思います。開発フォーラムには質問済みです。下記が質問内容です。
リンク内容

welcartのカートページの発送・支払方法のページをカスタマイズしています。解決したいことは、このページに出てくるカスタムオーダーフィールドで必須に設定したものが効かないことです。

まずカスタマイズの内容として「別の発送先の指定」をチェックしたときにでてくる入力フォームはお客様情報入力で使われる入力フォームでした。これはフィルターフックをつかって、出力している関数内をコピーしてif分岐で入力フォームを別にすることができました。

その次に入力フォームに使われているバリデーションの関数をフィルターフックで、名前だけ必須にしました。下記がそのコードです。

add_filter('usces_filter_delivery_check', 'my_filter_delivery_check2', 10); function my_filter_delivery_check2($mes) { $mes = ''; if ( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 1 ) { if ( WCUtils::is_blank($_POST["delivery"]["name1"]) ) $mes .= "届け先名を入力してください<br />"; // if ( trim($_POST["delivery"]["name3"]) == "" && USCES_JP ) // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />"; /*if ( WCUtils::is_blank($_POST["delivery"]["zipcode"]) ) $mes .= __('postal code is not correct', 'usces') . "<br />"; if ( $_POST["delivery"]["pref"] == __('-- Select --', 'usces') || $_POST["delivery"]["pref"] == '-- Select --' ) $mes .= __('enter the prefecture', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["address1"]) ) $mes .= __('enter the city name', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["address2"]) ) $mes .= __('enter house numbers', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["tel"]) ) $mes .= __('enter phone numbers', 'usces') . "<br />";*/ } return $mes; }

このやり方もコメントアウトしているだけなので、いい方法ではないと思います。とりあえずこの形で名前だけ入力チェックを行うことができました。

ただこの関数をfunctions.phpに書いたら、このwelcartが用意しているカスタムオーダーフィールドの必須が効かなくなってしまいました。

どこか別にカスタムオーダーフィールドの入力チェックが存在しているのか探しています。

何かご存知の方がいれば、ファイル名か関数名など教えて頂きたいと思います。ご教授お願いします。

追加 下記の関数が入力チェックをしている?

function delivery_check() { $mes = ''; if ( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 1 ) { if ( WCUtils::is_blank($_POST["delivery"]["name1"]) ) $mes .= __('Name is not correct', 'usces') . "<br />"; // if ( trim($_POST["delivery"]["name3"]) == "" && USCES_JP ) // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["zipcode"]) ) $mes .= __('postal code is not correct', 'usces') . "<br />"; if ( $_POST["delivery"]["pref"] == __('-- Select --', 'usces') || $_POST["delivery"]["pref"] == '-- Select --' ) $mes .= __('enter the prefecture', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["address1"]) ) $mes .= __('enter the city name', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["address2"]) ) $mes .= __('enter house numbers', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["tel"]) ) $mes .= __('enter phone numbers', 'usces') . "<br />"; } if ( !isset($_POST['offer']['delivery_method']) || (empty($_POST['offer']['delivery_method']) && !WCUtils::is_zero($_POST['offer']['delivery_method'])) ) { $mes .= __('chose one from delivery method.', 'usces') . "<br />"; } else { $d_method_index = $this->get_delivery_method_index((int)$_POST['offer']['delivery_method']); $country = $_SESSION['usces_entry']["delivery"]["country"]; $local_country = usces_get_base_country(); if($country == $local_country) { if($this->options['delivery_method'][$d_method_index]['intl'] == 1) { $mes .= __('Delivery method is incorrect. Can not specify an international flight.', 'usces') . "<br />"; } } else { if( WCUtils::is_zero($this->options['delivery_method'][$d_method_index]['intl']) ) { $mes .= __('Delivery method is incorrect. Specify the international flights.', 'usces') . "<br />"; } } } if ( !isset($_POST['offer']['payment_name']) ){ $mes .= __('chose one from payment options.', 'usces') . "<br />"; }else{ $payments = $this->getPayments($_POST['offer']['payment_name']); if('COD' == $payments['settlement']){ $total_items_price = $this->get_total_price(); $usces_entries = $this->cart->get_entry(); $materials = array( 'total_items_price' => $usces_entries['order']['total_items_price'], 'discount' => $usces_entries['order']['discount'], 'shipping_charge' => $usces_entries['order']['shipping_charge'], 'cod_fee' => $usces_entries['order']['cod_fee'], 'use_point' => ( isset($usces_entries['order']['use_point']) ) ? $usces_entries['order']['use_point'] : 0, ); $tax = $this->getTax( $total_items_price, $materials ); $total_items_price = $total_items_price + $tax; $cod_limit_amount = ( isset($this->options['cod_limit_amount']) && 0 < (int)$this->options['cod_limit_amount'] ) ? $this->options['cod_limit_amount'] : 0; if( 0 < $cod_limit_amount && $total_items_price > $cod_limit_amount ) $mes .= sprintf(__('A total products amount of money surpasses the upper limit(%s) that I can purchase in C.O.D.', 'usces'), usces_crform($this->options['cod_limit_amount'], true, false, 'return')) . "<br />"; } } if( isset($d_method_index) && isset($payments) ) { if($this->options['delivery_method'][$d_method_index]['nocod'] == 1) { if('COD' == $payments['settlement']) $mes .= __('COD is not available.', 'usces') . "<br />"; } } $mes = apply_filters('usces_filter_delivery_check', $mes); return $mes; }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kei344

2016/11/16 08:58

開発フォーラムには質問済みであれば、そのURLも質問文内に記載ください。
margin

2016/11/16 09:05

ありがとうございます。リンクを貼りました。
guest

回答2

0

自己解決

add_filter('usces_filter_delivery_check', 'my_filter_delivery_check2', 10); add_filter('usces_filter_delivery_check', 'usces_filter_delivery_check_custom_order', 15); function my_filter_delivery_check2($mes) { $mes = ''; if ( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 1 ) { if ( WCUtils::is_blank($_POST["delivery"]["name1"]) ) $mes .= "届け先名を入力してください<br />"; // if ( trim($_POST["delivery"]["name3"]) == "" && USCES_JP ) // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />"; /*if ( WCUtils::is_blank($_POST["delivery"]["zipcode"]) ) $mes .= __('postal code is not correct', 'usces') . "<br />"; if ( $_POST["delivery"]["pref"] == __('-- Select --', 'usces') || $_POST["delivery"]["pref"] == '-- Select --' ) $mes .= __('enter the prefecture', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["address1"]) ) $mes .= __('enter the city name', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["address2"]) ) $mes .= __('enter house numbers', 'usces') . "<br />"; if ( WCUtils::is_blank($_POST["delivery"]["tel"]) ) $mes .= __('enter phone numbers', 'usces') . "<br />";*/ } return $mes; }

上記の方法で解決しました。カスタムオーダーフィールド用の入力チェックの関数がありました。
これを一緒にフックをかけてあげることで、狙った動きになりました。

質問に付き合って頂きありがとうございます。

投稿2016/11/16 10:28

margin

総合スコア16

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

PHP

1function my_filter_delivery_check2($mes) { 2 $mes = ''; 3 /* 略 */ 4} 5```を 6```PHP 7function my_filter_delivery_check2( $mes = '' ) { 8 /* 略 */ 9} 10```とか?

投稿2016/11/16 09:10

kei344

総合スコア69398

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

margin

2016/11/16 09:14

今試してみましたがダメでした。追加でどの関数をフィルターしたのかを書いておきます。
kei344

2016/11/16 09:24

追記されたものはどこの何でしょうか。functions.phpに書かれているのでしょうか。
margin

2016/11/16 09:32

これはwelcartのプラグインのusceshop.class.phpというファイルに書かれています。フィルターフックなどは下記のURLのサイトを参考にしました。 http://welcustom.net/furigana-required/
kei344

2016/11/16 09:36

プラグイン本体を編集されているんですね。それはやめたほうが良いです。 プラグイン自体の更新時に毎回その変更を行うことになり、メンテナンスコストが増大します。
margin

2016/11/16 09:42

さきほど追加して書いたのはプラグイン本体に書かれてるものですが、最初に書かれているのはテーマのfunctions.phpに書いています。追加して書いた関数は、もともとどのような関数が使われているかをお知らせしようと書いたのですが、紛らわしくてすいません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問