• Hey,

    i want to add some fields to my checkout and then have them visible in my orders but something goes wrong and i don’t know what exactly.

    I have added 2 extra fields with this code:

    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'dropdown' );
    
    // Our hooked in function - $fields is passed via the filter!
    function dropdown( $fields ) {
         $fields['billing']['wenskaartje'] = array(
            'label'     => __('Wenst u een wenskaartje bij uw bestelling ?', 'woocommerce'),
        'placeholder'   => _x('dropdown', 'placeholder', 'woocommerce'),
        'required'  => false,
        'class'     => array('form-row-wide'),
        'clear'     => true,
        'type'      => 'select',
         'options'     => array(
            'option 1' => __('Ik wens geen wenskaartje bij mijn bestelling', 'woocommerce' ),
            'option 2' => __('Wenskaartje: Fijne verjaardag', 'woocommerce' ),
            'option 3' => __('Wenskaartje: Gefeliciteerd', 'woocommerce' ),
            'option 4' => __('Wenskaartje: Veel liefs', 'woocommerce' ),
            'option 5' => __('Wenskaartje: Van harte beterschap', 'woocommerce' ),
            'option 6' => __('Andere', 'woocommerce' )
            )//end of options
         );
    
         return $fields;
    }
    
    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         $fields['billing']['tekstkaartje'] = array(
            'label'     => __('Tekst op het wenskaartje', 'woocommerce'),
        'placeholder'   => _x('Uw text voor het kaartje', 'placeholder', 'woocommerce'),
        'required'  => false,
        'class'     => array('form-row-wide'),
        'type'		=> 'textarea',
        'clear'     => true
         );
    
         return $fields;
    }

    i guess my variables are wenskaartje and textkaartje. Now i try to display them in my admin but the fields stay empty. Any idea why ?

    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>'.__('Wenskaartje').':</strong> ' . get_post_meta( $order->id, 'wenskaartje', true ) . '</p>';
        echo '<p><strong>'.__('Text op het kaartje').':</strong> ' . get_post_meta( $order->id, 'textkaartje', true ) . '</p>';
    }

    Is it maybe because i still use wordpress 3.4.2 with woocommerce 1.6.5.2 ?

    https://www.ads-software.com/plugins/woocommerce/

  • The topic ‘Help with adding fields to checkout’ is closed to new replies.