我希望在选择后自动填写一些送货地址字段(如街道,社区和号码)。例如:
如果有人选择“01 Store - SãoPaulo”,它会自动填写位于圣保罗的商店地址。 (这只是一个例子)。
我已经尝试了数千个不同的插件,过滤器,钩子和动作......我看了一千个相关主题......但没有成功。
巴西的支付运营商和网关需要填写完整的地址表来处理付款。但客户只是讨厌它!
任何帮助?
实际上我正在使用一个技巧:我为每个地址创建一个产品变体,然后,我应用过滤器或类似的东西:
<?php
add_action( 'woocommerce_before_checkout_billing_form', 'testing_conditional' );
function testing_conditional ( ) {
global $woocommerce;
// loop through the cart checking the products
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
// checking the product variation ids
if( $_product->variation_id == 165, 170, 069 ) {
add_filter( 'default_checkout_postcode', 'change_default_checkout_postcode' );
function change_default_checkout_postcode() {
return '07400470'; // postcode
}
add_filter( 'default_checkout_shipping_address_1', 'change_default_checkout_shipping_address_1' );
function change_default_checkout_shipping_address_1() {
return 'Street Name';
}
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
function change_default_checkout_state() {
return 'SP'; // state code
}
add_filter( 'default_checkout_city', 'change_default_checkout_city' );
function change_default_checkout_city() {
return 'City Name';
}
}
}
}
?>
但我想在结帐页面添加一个条件。像这样:
<?php
function add_shipping_area_checkout_field( $fields ) {
$fields['shipping']['shipping_area'] = array(
'label' => __( 'Shipping Area', 'textdomain' ),
'placeholder' => _x( 'Shipping Area', 'placeholder', 'textdomain' ),
'required' => false,
'type' => 'select',
'options' => array(
'city 1' => 'City 1',
'city 2' => 'City 2',
'city 3' => 'City 3',
'city 4' => 'City 4',
),
'class' => array( 'form-row-wide', 'update_totals_on_change' ),
'clear' => true
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'add_shipping_area_checkout_field' );
// From here I don't know what to do
funtion conditional_field_value( $fields ) {
//if an user selects City 1
if $fields['shipping']['shipping_area'] = 'city 1' {
$fields['shipping']['address_1']['value'] = 'Street Name';
$fields['shipping']['city']['value'] = 'City Name';
$fields['shipping']['postcode']['value'] = 07400001;
}
//if an user selects City 2
if $fields['shipping']['shipping_area'] = 'city 2' {
$fields['shipping']['address_1']['value'] = 'Street Name 2';
$fields['shipping']['city']['value'] = 'City Name 2';
$fields['shipping']['postcode']['value'] = 07400002;
}
//if an user selects City 3
if $fields['shipping']['shipping_area'] = 'city 3' {
$fields['shipping']['address_1']['value'] = 'Street Name 3';
$fields['shipping']['city']['value'] = 'City Name 3';
$fields['shipping']['postcode']['value'] = 07000003;
}
}
?>
感谢您的支持