简体   繁体   中英

Updating WooCommerce Admin Shipping Order Fields

In functions.php I am trying to use this, but it is not working:

function rt_woocommerce_admin_shipping_fields( $fields ) {
    $fields['first_name']['value'] = $_GET['f'];
    $fields['last_name']['value'] = $_GET['l'];
    $fields['address_1']['value'] = $_GET['a'];
    $fields['address_2']['value'] = $_GET['b'];
    // etc
    // etc

    return $fields;
}

add_filter( 'woocommerce_admin_shipping_fields', 'rt_woocommerce_admin_shipping_fields' );

woocommerce_admin_billing_fields() works but the shipping function does not. Any advice? I need to update the fields with $_GET variables on page load. This works perfectly for the billing fields.

The array has label and show indexes for each item in shipping fields. There is no value index by default. See the woocommerce_admin_shipping_fields filter below.

self::$shipping_fields = apply_filters(
            'woocommerce_admin_shipping_fields',
            array(
                'first_name' => array(
                    'label' => __( 'First name', 'woocommerce' ),
                    'show'  => false,
                ),
                'last_name'  => array(
                    'label' => __( 'Last name', 'woocommerce' ),
                    'show'  => false,
                ),
                'company'    => array(
                    'label' => __( 'Company', 'woocommerce' ),
                    'show'  => false,
                ),
                'address_1'  => array(
                    'label' => __( 'Address line 1', 'woocommerce' ),
                    'show'  => false,
                ),
                'address_2'  => array(
                    'label' => __( 'Address line 2', 'woocommerce' ),
                    'show'  => false,
                ),
                'city'       => array(
                    'label' => __( 'City', 'woocommerce' ),
                    'show'  => false,
                ),
                'postcode'   => array(
                    'label' => __( 'Postcode / ZIP', 'woocommerce' ),
                    'show'  => false,
                ),
                'country'    => array(
                    'label'   => __( 'Country / Region', 'woocommerce' ),
                    'show'    => false,
                    'type'    => 'select',
                    'class'   => 'js_field-country select short',
                    'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
                ),
                'state'      => array(
                    'label' => __( 'State / County', 'woocommerce' ),
                    'class' => 'js_field-state select short',
                    'show'  => false,
                ),
                'phone'      => array(
                    'label' => __( 'Phone', 'woocommerce' ),
                ),
            )
        );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM