Scroll to top

How to check if Order Contains Product ID in woocommerce (if product is buy)?

Check if Order Contains Product ID in woocommerce

add_action( ‘woocommerce_thankyou’, ‘codekit_check_order_product_id’ );
 
function codekit_check_order_product_id( $order_id ){
$order = wc_get_order( $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 === ABC ) {
       // do something
   }
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *