如何将特定产品的“运送到其他地址”强制性设置为普通产品并将其禁用?我尝试使用此代码,但对我而言不起作用。
add_filter( 'woocommerce_available_payment_gateways', 'conditionally_disable_cod_payment_method', 10, 1);
function conditionally_disable_cod_payment_method( $gateways ){
$products_ids = array(793, 796);
foreach ( WC()->cart->get_cart() as $cart_item ){
$product_id = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->id : $cart_item['data']->get_id();
if (in_array( $cart_item['product_id'], $products_ids ) ){
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' );
}
}
return $gateways;
}
答案 0 :(得分:2)
请尝试以下操作:
let cars = ["Saab", "Volvo", "BMW"];
for(var i = 0; i < cars.length; i++)
{
document.body.innerHTML += '<div >' + cars[i] + '</div>';
}