簡體   English   中英

在 woocommerce 中為特定國家/地區顯示 state 的文本字段

[英]Show up text field for state in woocommerce for specific countries

woocommerce 中有一些國家,其中 State 字段根本不可見,我希望能夠在特定國家/地區顯示它們作為必需的文本字段。

我嘗試了一些在這里找到的解決方案,但它們似乎都是舊帖子,或者至少我無法讓它們工作。

我發現同一個片段的兩個非常相似的版本,一個在結帳頁面上拋出一堆錯誤,另一個是上面的那個,根本不起作用,它添加了所有國家/地區的運輸文本字段,而不僅僅是在法國:

function xa_filter_woocommerce_states( $states ) { 
    unset( $states['FR'] );
    var_dump( $states ) ;
    return $states;
};
add_filter( 'woocommerce_states', 'xa_filter_woocommerce_states', 10, 1 );

function xa_filter_woocommerce_get_country_locale( $locale ) { 
    $locale['FR']['state']['required'] = true;
    return $locale; 
};
add_filter( 'woocommerce_get_country_locale', 'xa_filter_woocommerce_get_country_locale', 10, 1 );

這工作正常,它可以滿足我的需要,但它會在結帳頁面上拋出一些文本(似乎不是錯誤),如下所示:

數組(76) { ["AF"]=> 數組(0) { } ["AO"]=> 數組(18) { ["BGO"]=> 字符串(5) "Bengo" ["BLU"]= > string(8) "Benguela" ["BIE"]=> string(4) "Bié" ["CAB"]=> string(7) "Cabinda" ["CNN"]=> string(6) "Cunene" ["HUA"]=> string(6) "Huambo" ["HUI"]=> string(6) "Huíla" ["CCU"]=> string(14) "Kuando Kubango" ["CNO"]=> string(12) "Kwanza-Norte" ["CUS"]=> string(10) "Kwanza-Sul" ["LUA"]=> string(6) "羅安達" ["LNO"]=> string(11) "Lunda-Norte" ["LSU"]=> 字符串(9)

我發現上面的代碼工作得很好,屏幕上的“錯誤”不是錯誤,而是來自變量的轉儲。 因此,刪除上述代碼的 1 行就可以了:

function xa_filter_woocommerce_states( $states ) { 
    unset( $states['FR'] );
    return $states;
};
add_filter( 'woocommerce_states', 'xa_filter_woocommerce_states', 10, 1 );

function xa_filter_woocommerce_get_country_locale( $locale ) { 
    $locale['FR']['state']['required'] = true;
    return $locale; 
};
add_filter( 'woocommerce_get_country_locale', 'xa_filter_woocommerce_get_country_locale', 10, 1 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM