Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Woocommerce管理页面中设置默认自定义帐单状态字段值_Php_Jquery_Wordpress_Woocommerce_Orders - Fatal编程技术网

Php 在Woocommerce管理页面中设置默认自定义帐单状态字段值

Php 在Woocommerce管理页面中设置默认自定义帐单状态字段值,php,jquery,wordpress,woocommerce,orders,Php,Jquery,Wordpress,Woocommerce,Orders,我想添加一些自定义计费状态,然后在管理面板中设置默认状态。到目前为止,我添加了如下状态(代码如下;也不确定这是否正确): 如何在管理面板中将默认值设置为StateA?您可以使用以下代码为国家/地区添加一些新的自定义州: add_filter('woocommerce_states','custom_woocommerce_states'); 功能自定义\u商业\u状态($states){ $states['XX']=数组(//XX是国家代码 “XX1”=>“状态1”, “XX2”=>“状态2”

我想添加一些自定义计费状态,然后在管理面板中设置默认状态。到目前为止,我添加了如下状态(代码如下;也不确定这是否正确):


如何在管理面板中将默认值设置为StateA?

您可以使用以下代码为国家/地区添加一些新的自定义州:

add_filter('woocommerce_states','custom_woocommerce_states');
功能自定义\u商业\u状态($states){
$states['XX']=数组(//XX是国家代码
“XX1”=>“状态1”,
“XX2”=>“状态2”
);
返回$states;

}
首先,当前代码中有一个错误

在添加(或编辑)账单(或发货)地址时的管理订单页面中,若要在选定国家为秘鲁(PE)时将自定义“PE1”设置为默认状态,请改用以下选项:

add_filter( 'woocommerce_states', 'custom_woocommerce_states_for_peru' );
function custom_woocommerce_states_for_peru( $states ) {
    // For PERU
    $states['PE'] = array(
        'PE1' => __('StateA', 'woocommerce'),
        'PE2' => __('StateB', 'woocommerce')
    );
    return $states;
}

// Admin orders: Set a default state for PERU country
add_action( 'admin_footer', 'custom_admin_shop_order_js' );
function custom_admin_shop_order_js() {
    global $pagenow, $post_type;

    if ( in_array( $pagenow, array('post-new.php', 'post.php') ) && 'shop_order' === $post_type ) :
    ?><script type='text/javascript'>
    jQuery( function($) {
        // Billing state
        $(document.body).on( 'change', 'select#_billing_country,select#_shipping_country', function(){
            var country       = 'PE', // Set country
                defaultState  = 'PE1', // Set default state (for country)
                parent        = $(this).parent().parent(),
                billingState  = parent.find('select#_billing_state'),
                shippingState = parent.find('select#_shipping_state');

            if( country === $(this).val() ) {
                if ( '' === billingState.val() ) {
                    billingState.val(defaultState).trigger("change");
                } else if ( '' === shippingState.val() ) {
                    shippingState.val(defaultState).trigger("change");
                }
            }
        });
    });
    </script><?php
    endif;
}
add_filter('woocommerce_states','custom_woocommerce_states_for_peru');
秘鲁的自定义商业州功能($states){
//秘鲁
$states['PE']=数组(
“PE1”=>”(StateA)、“woocommerce”),
“PE2”=>\uuuuu('StateB','woocommerce')
);
返回$states;
}
//管理员命令:设置秘鲁国家/地区的默认状态
添加操作('admin_footer'、'custom_admin_shop_order_js');
功能自定义\管理\商店\订单\ js(){
全局$pagenow,$post_类型;
如果(在数组($pagenow,array('post-new.php','post.php'))和&“shop\u order'=$post\u type中):
?>
jQuery(函数($){
//计费状态
$(document.body)。在('change',选择#(计费)(国家/地区),选择#(发货)(国家/地区)上的函数()中{
var country='PE',//设置国家/地区
defaultState='PE1',//设置默认状态(针对国家)
父项=$(this).parent().parent(),
billingState=parent.find('select#u billing_state'),
shippingState=parent.find('select#u shipping_state');
if(country==$(this.val()){
如果(''==billingState.val()){
billingState.val(defaultState.trigger(“更改”);
}如果(“”===shippingState.val()),则为else{
shippingState.val(defaultState).trigger(“更改”);
}
}
});
});

这在管理面板中不起作用。请反馈下面的答案。
add_filter( 'woocommerce_states', 'custom_woocommerce_states_for_peru' );
function custom_woocommerce_states_for_peru( $states ) {
    // For PERU
    $states['PE'] = array(
        'PE1' => __('StateA', 'woocommerce'),
        'PE2' => __('StateB', 'woocommerce')
    );
    return $states;
}

// Admin orders: Set a default state for PERU country
add_action( 'admin_footer', 'custom_admin_shop_order_js' );
function custom_admin_shop_order_js() {
    global $pagenow, $post_type;

    if ( in_array( $pagenow, array('post-new.php', 'post.php') ) && 'shop_order' === $post_type ) :
    ?><script type='text/javascript'>
    jQuery( function($) {
        // Billing state
        $(document.body).on( 'change', 'select#_billing_country,select#_shipping_country', function(){
            var country       = 'PE', // Set country
                defaultState  = 'PE1', // Set default state (for country)
                parent        = $(this).parent().parent(),
                billingState  = parent.find('select#_billing_state'),
                shippingState = parent.find('select#_shipping_state');

            if( country === $(this).val() ) {
                if ( '' === billingState.val() ) {
                    billingState.val(defaultState).trigger("change");
                } else if ( '' === shippingState.val() ) {
                    shippingState.val(defaultState).trigger("change");
                }
            }
        });
    });
    </script><?php
    endif;
}