Created
February 2, 2018 10:02
-
-
Save heldervilela/9b016f42950c299612a6d9e659030d49 to your computer and use it in GitHub Desktop.
How to Hook Into WooCommerce to Trigger Something After an Order is Placed
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
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1); | |
function custom_process_order($order_id) { | |
$order = new WC_Order( $order_id ); | |
$myuser_id = (int)$order->user_id; | |
$user_info = get_userdata($myuser_id); | |
$items = $order->get_items(); | |
foreach ($items as $item) { | |
if ($item['product_id']==24) { | |
// Do something clever | |
} | |
} | |
return $order_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment