2
WOOCommerceでは、ショッピングカートの商品に'Varifocal'
の属性があるかどうかをチェックしたいと思います(チェックアウトフィールドの表示/非表示が可能です) 。カート内の特定の属性値が使用されていることを確認する
私は、属性 'varifocal'を持つすべてのバリエーションのidの配列を取得するのに苦労しています。誰かが私を正しい方向に向けることができれば、本当に感謝しています。
分類法はpa_lenses
です。
私は現在、次の機能があります。
function varifocal() {
// Add product IDs here
$ids = array();
// Products currently in the cart
$cart_ids = array();
// Find each product in the cart and add it to the $cart_ids array
foreach(WC()->cart->get_cart() as $cart_item_key => $values) {
$cart_product = $values['data'];
$cart_ids[] = $cart_product->get_id();
}
// If one of the special products are in the cart, return true.
if (! empty(array_intersect($ids, $cart_ids))) {
return true;
} else {
return false;
}
}
もっと良い解決策。私はそれをテストし、それは動作します。どうもありがとうございました! – PieterM