Home Forums Plugins WooCommerce Email Template Customizer Changer la valeur des champs personnalisés dans les emails

Changer la valeur des champs personnalisés dans les emails

  • Author
    Posts
  • #105602

    sahafi
    Participant

    Hi,
    Please could someone bring me a way out.

    Here the code:

    /**
    * Add custom billing fields.
    */
    add_filter( ‘woocommerce_billing_fields’ , ‘js_sora_add_billing_fields’ );

    function js_sora_add_billing_fields( $fields ) {

    $fields[‘billing_gender’] = array(
    ‘type’ => ‘select’,
    ‘label’ => __(‘Gender’, ‘sora’),
    ‘options’ => array(
    ” => __( ‘Select options’, ‘sora’ ),
    ‘1’ => __(‘Miss’, ‘sora’),
    ‘2’ => __(‘Mrs’, ‘sora’),
    ‘3’ => __(‘Mr’, ‘sora’),
    ),
    ‘placeholder’ => _x(‘Select options’, ‘placeholder’, ‘sora’),
    ‘required’ => true,
    ‘priority’ => 10,
    ‘class’ => array(‘form-row-first’),
    ‘input_class’ => array(‘wc-enhanced-select’),
    ‘clear’ => true
    );

    wc_enqueue_js( ”
    jQuery( ‘:input.wc-enhanced-select’ ).filter( ‘:not(.enhanced)’ ).each( function() {
    var select2_args = { minimumResultsForSearch: 5 };
    jQuery( this ).select2( select2_args ).addClass( ‘enhanced’ );
    });”
    );

    return $fields;
    }

    /**
    * Update the order meta with field value.
    */
    add_action( ‘woocommerce_checkout_update_order_meta’, ‘js_sora_field_update_order_meta’ );

    function js_sora_field_update_order_meta( $order_id ) {
    if ( ! empty( $_POST[‘billing_gender’] ) ) {
    update_post_meta( $order_id, ‘billing_gender’, sanitize_text_field( $_POST[‘billing_gender’] ) );
    }
    }

    How to change numeric values to text in emails only.
    1 == some text
    2 == some text
    etc…

    PS : I use shortcode [wec_order_meta key=’billing_gender’]

    example : if the customer selects option 3
    change ‘3’ to ‘Cher Monsieur’ / in emails

    Results : [wec_order_meta key=’billing_gender’] {first_name} {last_name},
    == Cher Monsieur Jhon Doe

    I hope to have been clear

    Regards

You must be logged in to see replies to this topic. Click here to login or register