現在ローカル環境で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;
}
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
check解決した方法
+1
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;
}
上記の方法で解決しました。カスタムオーダーフィールド用の入力チェックの関数がありました。
これを一緒にフックをかけてあげることで、狙った動きになりました。
質問に付き合って頂きありがとうございます。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
0
function my_filter_delivery_check2($mes) {
$mes = '';
/* 略 */
}
を
function my_filter_delivery_check2( $mes = '' ) {
/* 略 */
}
とか?
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.20%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
kei344
2016/11/16 17:58
開発フォーラムには質問済みであれば、そのURLも質問文内に記載ください。
margin
2016/11/16 18:05
ありがとうございます。リンクを貼りました。