【发布时间】:2017-05-09 07:49:24
【问题描述】:
在 WooCommerce 中,我想检查购物车中的产品是否具有属性 '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;
}
}
【问题讨论】:
标签: php wordpress woocommerce cart variations