Skip to content

Instantly share code, notes, and snippets.

@gthayer
Created September 30, 2016 15:19
Show Gist options
  • Save gthayer/7835e800483ecce630fe7266e466933e to your computer and use it in GitHub Desktop.
Save gthayer/7835e800483ecce630fe7266e466933e to your computer and use it in GitHub Desktop.
// TODO: look into basing this off order value.
//add_filter( 'woocommerce_email_enabled_new_renewal_order', 'unhook_those_pesky_emails', 20, 2 );
//add_filter( 'woocommerce_email_enabled_customer_renewal_invoice', 'unhook_those_pesky_emails', 20, 2 );
add_filter( 'woocommerce_email_enabled_customer_new_order', 'unhook_those_pesky_emails', 20, 2 );
function unhook_those_pesky_emails( $active, $order ) {
//var_dump($order);
//exit;
if ( ! isset($order) ) {
return $active;
}
var_dump($order);
$items = $order->get_items();
$active = false;
foreach ( $items as $item ) {
if ( isset( $item['variation_id'] ) ) {
$product = wc_get_product( $item['variation_id'] );
} else {
$product = wc_get_product( $item['product_id'] );
}
$price = $product->get_price();
if ( 0 != $price ) {
$active = true;
break;
}
}
return $active;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment