Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Created August 6, 2018 20:58
Show Gist options
  • Save NickGreen/8560ab5a946e72662d247ec31251b7ad to your computer and use it in GitHub Desktop.
Save NickGreen/8560ab5a946e72662d247ec31251b7ad to your computer and use it in GitHub Desktop.
Do something if order has subscription product in it
<?php
$order = wc_get_order( $order_id );
$sub_in_order = false;
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
if ( has_term( 'subscription', 'product_type', $product_id ) || has_term( 'variable-subscription', 'product_type', $product_id ) ) {
$sub_in_order = true;
break;
}
}
if ( $sub_in_order ) {
// DO THINGS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment