WordPress WooCommerce检测某个产品ID Product ID 是否在订单中 代码实例

在WordPress的主题WooCommerce商城开发插件中,我们需要检测一个产品id是否在某个订单中,下面我们记录一下代码实例

function check_order_product_id($order_id,$the_product_id) {     $order = wc_get_order((int)$order_id);     $items = $order->get_items();     foreach ($items as $item_id => $item) {         $product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();         if ($product_id === (int)$the_product_id) {             return true;         }     }     return false; } 

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】