Skip to content

Instantly share code, notes, and snippets.

@heldervilela
Created February 2, 2018 10:02
Show Gist options
  • Save heldervilela/9b016f42950c299612a6d9e659030d49 to your computer and use it in GitHub Desktop.
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
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