【发布时间】:2021-06-24 08:00:59
【问题描述】:
我试图在 WooComerce 结帐中仅显示特定产品的有限国家/地区。
我能够成功获取购物车产品 ID,但无法在函数之外获取它。
// hide countries
function get_cart_product_id() {
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item['data'];
if(!empty($product)){
$live_pro = $product->get_id();
}
}
return $live_pro;
global $live_pro;
}
global $live_pro;
echo $live_pro; // Donesn't echo anything here. Below if also not working
if ($live_pro == 435925 || $live_pro == 435929 || $live_pro == 435930 || $live_pro == 435931 || $live_pro == 435932 ) {
add_filter( 'woocommerce_countries', 'bbloomer_custom_woocommerce_countries' );
}
function bbloomer_custom_woocommerce_countries( $country ) {
$country = array(
'ES' => 'Spain',
'PT' => 'Portugal',
'FR' => 'France',
);
return $country;
}
有什么建议可以帮助我找到解决方案吗?
【问题讨论】:
-
return行之后函数范围内的任何内容都不会被执行。
标签: php wordpress woocommerce checkout countries