首先,如果这不是问这个的地方,请告诉我,我会将其删除。
我从这段代码中获得了产品:
$products = $this->getCategoryItems( $category->slug, true );
这是var_dump($ products)
array(2) { [0]=> object(WC_Product_Simple)#9164 (5) { ["id"]=> int(598795) ["post"]=> object(WP_Post)#9163 (25) { ["ID"]=> int(598795) ["post_author"]=> string(1) "0" ["post_date"]=> string(19) "2015-10-05 06:50:02" ["post_date_gmt"]=> string(19) "2015-10-05 06:50:02" ["post_content"]=> string(28) "KARAOKE CON USB KARAOKESTAR2" ["post_title"]=> string(28) "KARAOKE CON USB KARAOKESTAR2" ["post_excerpt"]=> string(28) "KARAOKE CON USB KARAOKESTAR2" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(28) "karaoke-con-usb-karaokestar2" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-12-30 21:01:33" ["post_modified_gmt"]=> string(19) "2015-12-30 21:01:33" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(68) "http://mydwebsite.com/producto/karaoke-con-usb-karaokestar2/" ["menu_order"]=> int(0) ["post_type"]=> string(7) "product" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" ["thumbnail"]=> string(83) "http://mywebsite.com/wp-content/uploads/2015/10/karaoke-star2mkii_p_b3.jpg" } ["product_type"]=> string(6) "simple" ["shipping_class":protected]=> string(0) "" ["shipping_class_id":protected]=> int(0) } [1]=> object(WC_Product_Simple)#9155 (5) { ["id"]=> int(598797) ["post"]=> object(WP_Post)#9159 (25) { ["ID"]=> int(598797) ["post_author"]=> string(1) "0" ["post_date"]=> string(19) "2015-10-05 06:50:02" ["post_date_gmt"]=> string(19) "2015-10-05 06:50:02" ["post_content"]=> string(40) "KARAOKE 2X75W CON BLUETOOTH KARAOKESTAR4" ["post_title"]=> string(40) "KARAOKE 2X75W CON BLUETOOTH KARAOKESTAR4" ["post_excerpt"]=> string(40) "KARAOKE 2X75W CON BLUETOOTH KARAOKESTAR4" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(40) "karaoke-2x75w-con-bluetooth-karaokestar4" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-12-30 21:01:34" ["post_modified_gmt"]=> string(19) "2015-12-30 21:01:34" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(80) "http://mywebiste.com/producto/karaoke-2-con-bluetooth-karaoke/" ["menu_order"]=> int(0) ["post_type"]=> string(7) "product" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" ["thumbnail"]=> string(81) "http://myewbsite.com/wp-content/uploads/2015/12/karaoke-star_b2.jpg" } ["product_type"]=> string(6) "simple" ["shipping_class":protected]=> string(0) "" ["shipping_class_id":protected]=> int(0) }
现在我需要检查一些并删除产品,如果为true:
foreach($products as $prod)
{
if( something I need is true)
{
//I need to remove $prod from $products but I don't have any idea how.
}
}
如何从产品阵列中删除此产品?