你好,我想为结帐创建自定义代码

时间:2019-07-09 20:03:57

标签: php wordpress woocommerce

例如,如果所选国家/地区为埃及,则显示每个城市的下拉列表

我尝试了下面显示下拉列表的代码,但我想像我编写的示例一样做出有条件的陈述

function ace_change_city_to_dropdown( $fields ) {
    $cities = array(
        'Heliopolis',
        'El sherouk',
        'El sherouk1',
        'El sherouk2',
        'El sherouk3',
        'El sherouk4',
        'El sherouk5',
    );
    $city_args = wp_parse_args( array(
        'type' => 'select',
        'options' => array_combine( $cities, $cities ),
        'input_class' => array('wc-enhanced-select')
    ), $fields['shipping']['shipping_city']);

    $fields['shipping']['shipping_city'] = $city_args;
    $fields['billing']['billing_city'] = $city_args;
    wc_enqueue_js( "
        jQuery(':input.wc-enhanced-select').filter(':not(.enhanced)').each( function() {
            var select2_args = { minimumResultsForSearch: 2 };
            jQuery( this ).select2( select2_args ).addClass('enhanced');
        });"
    );
    return $fields;
 }
 add_filter( 'woocommerce_checkout_fields', 'ace_change_city_to_dropdown');

0 个答案:

没有答案