0

チェックアウトフォームに2つのフィールドを追加したいと思います。オフロード部品を販売するウェブサイトを運営しています。お客様が車両の年式/メーカー/モデルを入力できるテキストボックスが欲しいのですが。部品が彼らの車両と互換性があることを私たちに確認させたくない場合は、私は彼らに同じように言っているボックスをチェックしなければならないことを望みます。

http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/-レッスン3は、フィールドを追加するのに最適です....しかし、作成方法がわかりませんこのチェックボックスは、テキストボックスが空の場合にのみ必要です。

TIA

4

2 に答える 2

0

woothemesについてはよくわかりませんが、基本的な「フォームに入力するとチェックボックスが無効になります」というコードがあります。クエリにPHPのタグを付けていないため、これはすべて基本的なJavaScriptです。

<!DOCTYPE html>
<meta charset="UTF-8">
<title>test</title>

<input type="checkbox" id="myCheckBox"></input>
<input type="text" name="myTextBox" id="checking" onblur="myTextBox(this);" onmousedown="myTextBoxActive(this);" />

<script>  


function myTextBox(field) {
    if (field.value == '') {
        document.getElementById('myCheckBox').disabled=false;
    }
}


function myTextBoxActive(field) {
    if (field.value == '') {
        document.getElementById('myCheckBox').disabled=true;
    }
}




</script>
于 2013-03-16T05:30:22.860 に答える
0

昨夜は遅かったと思います。答えは簡単です。以下は、元の質問に投稿したリンクからのものです。

/**
 * Process the checkout
 **/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');

function my_custom_checkout_field_process() {
    global $woocommerce;

    // Check if set, if its not set add an error.
    if (!$_POST['my_field_name'])
        $woocommerce->add_error( __('Please enter something into this new shiny field.') );
}

実行する必要があるのは次のとおりです。

if (!$_POST['my_field_name'])
        $woocommerce->add_error( __('Please enter something into this new shiny field.') );

次のように変更:

if (!($_POST['my_field_name'] || $_POST['my_checkbox']))
        $woocommerce->add_error( __('Please enter something into this new shiny field or check the box.') );
于 2013-03-16T15:20:41.527 に答える