我正在通过以下代码在woocommerce购物车的结算部分创建自定义字段:
add_filter( 'woocommerce_default_address_fields', 'fts_cdek_fields_address' );
function fts_cdek_fields_address($fields){
$fields['cdek_city_id'] = array(
'type' => 'text',
'label' => __('Shipping city id. Technically needed.', $WCFCT),
'placeholder' => '',
'class' => array( 'wc_fts_cdek_hide','update_totals_on_change','form-row-wide','address-field' ),
'required' => false,
'clear' => false,
'label_class' => array( 'wc_fts_cdek_hide' )
);
return $fields;
}
function fts_cdek_fields_error(){
// Check if thechnical field is clear => user didn't enter the city or entered it wrong! (Without cdek api and autocomplete)
if(!isset($_POST['billing_cdek_city_id'])){
wc_add_notice( __( 'Please reenter city in shipping area using autocomplete.' ), 'error' );
}
}
add_action('woocommerce_checkout_update_order_meta', 'fts_cdek_fields_save');
function fts_cdek_fields_save( $order_id ){
if( !empty( $_POST['billing_cdek_city_id'] ) ){
update_post_meta( $order_id, 'CDEK city ID', $_POST['billing_cdek_city_id'] );
}
}
我想在woocommerce自定义发货(calculate_shipping)中将我的字段值添加到$ package变量。如何在那里添加数据?