Created
January 15, 2020 11:05
-
-
Save chrismademe/c69d6af0fb29d98ffe7c9bf230843ba8 to your computer and use it in GitHub Desktop.
WooCommerce - order_has_product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Order Has Product | |
* | |
* Checks a WooCommerce order to see if it contains | |
* a given product ID | |
* | |
* @param object $order | |
* @param int $product_id | |
* @return bool | |
*/ | |
function order_has_product( $order, $product_id ) { | |
$items = $order->get_items(); | |
$has_product = false; | |
foreach ( $items as $item ) { | |
if ( $item->get_product_id() === $product_id ) { | |
$has_product = true; | |
break; | |
} | |
} | |
return $has_product; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment