在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; }  
				 
 
 
 
                                     
                                     
                                     
                                     
                                    
评论已关闭