1
我使用下面的代码,如果一个产品ID是在购物车中,如果是这样,添加额外的校验字段:检查多个产品ID在购物车中WooCommerce
add_action('woocommerce_after_order_notes', 'conditional_checkout_field');
function conditional_checkout_field($checkout) {
echo '<div id="conditional_checkout_field">';
$product_id = 326;
$product_cart_id = WC()->cart->generate_cart_id($product_id);
$in_cart = WC()->cart->find_product_in_cart($product_cart_id);
// Check if the product is in the cart and show the custom field if it is
if ($in_cart) {
echo '<h3>'.__('Products in your cart require the following information').'</h3>';
woocommerce_form_field('custom_field_license', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('License Number'),
'placeholder' => __('Placeholder to help describe what you are looking for'),
), $checkout->get_value('custom_field_license'));
}
}
这一切正常。但是,如何检查购物车中的多个产品ID?例如,如果产品ID 326或245在购物车中,请显示条件结账字段?我觉得这可能很简单,但我不知道如何去做。
完美工作。谢谢。 – jasonTakesManhattan