- Statut : non résolu
- Ce sujet contient 10 réponses, 3 participants et a été mis à jour pour la dernière fois par roar, le il y a 9 années et 11 mois.
-
AuteurMessages
-
5 octobre 2014 à 22 h 33 min #542730
Bonjour,
Ma configuration WP actuelle
– Version de WordPress : 4
– Version de PHP/MySQL :
– Thème utilisé : wildcat
– Extensions en place :
– Nom de l’hebergeur : ovh
– Adresse du site : http://test.taldeak.fr/wordpressProblème(s) rencontré(s) :
Bonjour,
J’ai ajouté des champs sur la page « checkout », mais ces champs une fois remplis et la commande validée n’apparaissent pas sur le résumé de la commande.
Voici le code utilisé. qu’est ce qui m’échappe ?
/**
* Add the field to the checkout
*/
addaction( ‘woocommerceafterordernotes’, ‘mycustomcheckout_field’ );
function my_custom_checkout_field( $checkout ) {
echo ‘<div id="my_custom_checkout_field"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 1’),
‘placeholder’ => __(‘Prénom’),
‘required’ => true,
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(interlocuteur principal)’),
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘ ‘),
‘placeholder’ => __(‘Numéro de passeport / CI’),
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 2’),
‘placeholder’ => __(‘Prénom’),
‘required’ => false,
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(si applicable)’),
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘ ‘),
‘placeholder’ => __(‘Numéro de passeport / CI’),
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 3’),
‘placeholder’ => __(‘Prénom’),
‘required’ => false,
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(si applicable)’),
), $checkout->get_value( ‘my_field_name’ ));
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘ ‘),
‘placeholder’ => __(‘Numéro de passeport / CI’),
), $checkout->get_value( ‘my_field_name’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
addaction(‘woocommercecheckoutprocess’, ‘mycustomcheckoutfield_process’);
function mycustomcheckoutfieldprocess() {
// Check if set, if its not set add an error.
if ( ! $POST[‘myfieldname’] )
wcaddnotice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’ );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;Merci d’avance 🙂
8 octobre 2014 à 8 h 18 min #975632J’ai réussi à résoudre le problème de mon côté en voulant comme toi créer des custums fields.
Je jette un oeil et je reviens vers toi8 octobre 2014 à 9 h 17 min #975633Voilà j’ai la solution.
Ça me rappelle des jours et des heures de prises de tête pour avoir moi aussi mes customs fields qui apparaissent dans mon administrateur de résumé de commande/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );
function my_custom_checkout_field( $checkout ) {
echo ‘<div id="my_custom_checkout_field"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 1’),
‘placeholder’ => __(‘Prénom’),
‘required’ => true,
), $checkout->get_value( ‘my_field_name’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field_process’);
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’ );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field2’ );
function my_custom_checkout_field2( $checkout ) {
echo ‘<div id="my_custom_checkout_field2"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name2’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(interlocuteur principal)’),
), $checkout->get_value( ‘my_field_name2’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field2_process’);
function my_custom_checkout_field2_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name2’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field2_update_order_meta’ );
function my_custom_checkout_field2_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name2’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name2’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field2_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field2_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;Explication:
Pour chaque custom field il faut les 4 étapes incontournables « Add the field to checkout » + « Process the checkout » + « Update the order meta with field value » + « Display field value on the order edit page ».Donc là je t’en ai fait que deux.
Tu dois répéter l’opération pour tes autres champs personnalisés.Tu remarqueras que pour ton second custom field (avec les 4 étapes incontournables) j’ai rajouté le chiffre « 2 » à certains endroits. Pour la simple et bonne raison que chaque custom field ne peut pas avoir la même dénomination sinon dans le résumé de ta commande dans ton administrateur, ca sera la pagaille.
Ainsi pour ton 3ème custom field, tu remplaceras « 2 » par « 3 ». Pour ton 4ème, « 4 » etc…
Normalement tu verras que tout tes customs fields apparaitront normalement dans ton administration de commande.Dis moi si cela fonctionne.
8 octobre 2014 à 12 h 30 min #975634whaoo !! MERCI !!
je teste ça tout de suite et je te confirme. mais vraiment merci pour ton aide et le temps que tu y as passé !!8 octobre 2014 à 17 h 34 min #975635petite question espoontintin : concernant cette partie
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field4_process’);
function my_custom_checkout_field4_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name4’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}qu’est ce que je dois changer si je ne veux pas que ce champ soit obligatoire? (à part enlever ‘Merci de compléter ces champs’ bien sûr)
Merci d’avance !!! 🙂
8 octobre 2014 à 18 h 10 min #975636Bon voici mon code une fois édité comme tu me l’a conseillé, mais il doit y avaoir un souci car j’obtiens un messgae d’erreur quand j’essaie de l’insérer dans mon le fichier functions.php de mon child theme…
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );
function my_custom_checkout_field( $checkout ) {
echo ‘<div id="my_custom_checkout_field"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 1’),
‘placeholder’ => __(‘Prénom’),
‘required’ => true,
), $checkout->get_value( ‘my_field_name’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field_process’);
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’ );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field2’ );
function my_custom_checkout_field2( $checkout ) {
echo ‘<div id="my_custom_checkout_field2"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name2’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(interlocuteur principal)’),
), $checkout->get_value( ‘my_field_name2’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field2_process’);
function my_custom_checkout_field2_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name2’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field2_update_order_meta’ );
function my_custom_checkout_field2_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name2’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name2’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field2_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field2_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field3’ );
function my_custom_checkout_field3( $checkout ) {
echo ‘<div id="my_custom_checkout_field3"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name3’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘placeholder’ => __(‘ Numéro de passeport / CI’),
‘label’ => __( »),
), $checkout->get_value( ‘my_field_name3’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field3_process’);
function my_custom_checkout_field3_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name3’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field3_update_order_meta’ );
function my_custom_checkout_field3_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name3’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name3’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field3_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field3_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field4’ );
function my_custom_checkout_field4( $checkout ) {
echo ‘<div id="my_custom_checkout_field4"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name4’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 2’),
‘placeholder’ => __(‘Prénom’),
‘required’ => false,
), $checkout->get_value( ‘my_field_name4’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field4_process’);
function my_custom_checkout_field4_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name4’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field4_update_order_meta’ );
function my_custom_checkout_field4_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name4’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name4’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field4_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field4_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field5’ );
function my_custom_checkout_field5( $checkout ) {
echo ‘<div id="my_custom_checkout_field5"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name5’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(si applicable)’),
), $checkout->get_value( ‘my_field_name5’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field5_process’);
function my_custom_checkout_field5_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name5’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field5_update_order_meta’ );
function my_custom_checkout_field5_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name5’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name5’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field5_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field5_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field6’ );
function my_custom_checkout_field6( $checkout ) {
echo ‘<div id="my_custom_checkout_field6"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name6’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘placeholder’ => __(‘Numéro de passeport / CI’),
‘label’ => __( »),
), $checkout->get_value( ‘my_field_name6’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field6_process’);
function my_custom_checkout_field6_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name6’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field6_update_order_meta’ );
function my_custom_checkout_field6_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name6’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name6’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field6_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field6_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field7’ );
function my_custom_checkout_field7( $checkout ) {
echo ‘<div id="my_custom_checkout_field7"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name7’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-first’),
‘label’ => __(‘Passager 2’),
‘placeholder’ => __(‘Prénom’),
‘required’ => false,
), $checkout->get_value( ‘my_field_name7’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field7_process’);
function my_custom_checkout_field7_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name7’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field7_update_order_meta’ );
function my_custom_checkout_field7_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name7’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name7’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field7_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field7_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field8’ );
function my_custom_checkout_field8( $checkout ) {
echo ‘<div id="my_custom_checkout_field8"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name8’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-last’),
‘placeholder’ => __(‘Nom’),
‘label’ => __(‘(si applicable)’),
), $checkout->get_value( ‘my_field_name8’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field8_process’);
function my_custom_checkout_field8_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name8’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field8_update_order_meta’ );
function my_custom_checkout_field8_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name8’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name8’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field8_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field8_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field9’ );
function my_custom_checkout_field9( $checkout ) {
echo ‘<div id="my_custom_checkout_field9"><h3>‘ . __(‘Informations Passager(s)’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name9’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘placeholder’ => __(‘Numéro de passeport / CI’),
‘label’ => __( »),
), $checkout->get_value( ‘my_field_name9’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field9_process’);
function my_custom_checkout_field9_process() {
// Check if set, if its not set add an error.
if ( ! $POST[‘my_field_name9’] )
wc_add_notice( _( ‘Merci de compléter ces champs.’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field9_update_order_meta’ );
function my_custom_checkout_field9_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name9’] ) ) {
update_post_meta( $order_id, ‘Informations Passager(s)’, sanitize_text_field( $_POST[‘my_field_name9’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field9_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field9_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Informations Passager(s)’).’:</strong> ‘ . get_post_meta( $order->id, ‘Informations Passager(s)’, true ) . ‘</p>‘;une idée de ce qui bloque ??
:boulet:8 octobre 2014 à 18 h 37 min #975637J’ai regardé uniquement le premier champ.
Voici mes remarques:
« Informations passagers » est-il le titre unique qui concerne tous tes champs qui suivent? Si oui pas la peine de le remettre par la suite.
Ensuite j’ai noté des choses à corriger:
– dans « Add the field to the checkout » essaye plutôt: ‘class’ => array(‘my-field-class form-row-wide’),
– dans « Process the checkout » , corrige « add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field_process’);
– dans « update the order meta with field value » corrige Informations passagers par le label de »add the field to the checkout ». A savoir « Passager 1 ». « Informations passagers étant le titre général de l’ensemble de tes champs personnalisés.
– dans « display field value on the order edit page », même chose. remplace les 2 « informations passagers » par « passager 1 »Je te conseille de faire champ par champ. Tu en essayes un, tu vérifies et si ca fonctionne tu t’attaques au second.
En n’oubliant pas de nommer pour le deuxième champ8 octobre 2014 à 18 h 41 min #975638je n’ai pas fini ma phrase…lol
En n’oubliant pour le deuxième champ de rajouter « 2 » là où je te l’ai indiqué dans mon précédent post.
Et « 3 » pour le troisième etc…Je reste connecté fais des essais et dis moi
8 octobre 2014 à 19 h 10 min #975639En regardant de plus près tu avais en effet un peu mélangé titre, avec le label de ton champ et le placeholder (texte en filigrane qui apparaît dans le champ)
Si j’ai bien compris la structure de tes champs voici ce que cela donne pour le passager 1 qui doit renseigner: prénom, nom et numéro de passeport:/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );
function my_custom_checkout_field( $checkout ) {
echo ‘<div id="my_custom_checkout_field"><h3>‘ . __(‘Informations passager 1’) . ‘</h3>‘;
woocommerce_form_field( ‘my_field_name’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘Prénom passager 1’),
‘required’ => true,
‘placeholder’ => __(‘(prénom)’),
), $checkout->get_value( ‘my_field_name’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field_process’);
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST[‘my_field_name’] )
wc_add_notice( __( ‘Merci de compléter ces champs’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’ );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name’] ) ) {
update_post_meta( $order_id, ‘Prénom passager 1’, sanitize_text_field( $_POST[‘my_field_name’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Prénom passager 1′).’:</strong> ‘ . get_post_meta( $order->id, ‘Prénom passager 1’, true ) . ‘</p>‘;
}
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field2’ );
function my_custom_checkout_field2( $checkout ) {
echo ‘<div id="my_custom_checkout_field2">‘;
woocommerce_form_field( ‘my_field_name2’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘Nom passager 1’),
‘required’ => true,
‘placeholder’ => __(‘(nom)’),
), $checkout->get_value( ‘my_field_name2’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field2_process’);
function my_custom_checkout_field2_process() {
// Check if set, if its not set add an error.
if ( ! $_POST[‘my_field_name2’] )
wc_add_notice( __( ‘Merci de compléter ces champs’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field2_update_order_meta’ );
function my_custom_checkout_field2_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name2’] ) ) {
update_post_meta( $order_id, ‘Nom passager 1’, sanitize_text_field( $_POST[‘my_field_name2’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field2_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field2_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Nom passager 1′).’:</strong> ‘ . get_post_meta( $order->id, ‘Nom passager 1’, true ) . ‘</p>‘;
}
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field3’ );
function my_custom_checkout_field3( $checkout ) {
echo ‘<div id="my_custom_checkout_field3">‘;
woocommerce_form_field( ‘my_field_name3’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘Passeport passager 1’),
‘required’ => true,
‘placeholder’ => __(‘(n° de passeport)’),
), $checkout->get_value( ‘my_field_name3’ ));
echo ‘</div>‘;
}
/**
* Process the checkout
*/
add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field3_process’);
function my_custom_checkout_field3_process() {
// Check if set, if its not set add an error.
if ( ! $_POST[‘my_field_name3’] )
wc_add_notice( __( ‘Merci de compléter ces champs’ ), ‘error’ );
}
/**
* Update the order meta with field value
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field3_update_order_meta’ );
function my_custom_checkout_field3_update_order_meta( $order_id ) {
if ( ! empty( $_POST[‘my_field_name3’] ) ) {
update_post_meta( $order_id, ‘Passeport passager 1’, sanitize_text_field( $_POST[‘my_field_name3’] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘my_custom_checkout_field3_display_admin_order_meta’, 10, 1 );
function my_custom_checkout_field3_display_admin_order_meta($order){
echo ‘<p><strong>‘.__(‘Passeport passager 1′).’:</strong> ‘ . get_post_meta( $order->id, ‘Passeport passager 1’, true ) . ‘</p>‘;19 octobre 2014 à 2 h 56 min #975640merci beaucoup pour ton aide.
je suis partie sur une autre solution finalement, plus simple : faire entrer ces infos sur la page produit plutot qu’au moment du checkout.
27 décembre 2014 à 16 h 52 min #975641j’ai lu les topic d’autre….
il y a des choses que je n’arrive pas à comprendre
où je tape mon code ?
sur mon wordpress ou un plugin les deux
On me parle qui faut Il faut initialiser la metaboxle code : add_action(‘add_meta_boxes’,’initialisation_metaboxes’);
function initialisation_metaboxes(){où je dois taper ce code
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.