Advertisement
majeedraza

WooCommerce - woocommerce_thankyou hook demo

Apr 13th, 2015
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2.   // Demo of woocommerce_thankyou hook
  3.   // code goes in functions.php for child theme
  4.   add_action ('woocommerce_thankyou', 'myfunction');
  5.   function myfunction($order_id) {
  6.     $order = new WC_Order($order_id);
  7.     $items = $order->get_items();
  8.     foreach ($items as $item) {
  9.       $item_metas = $item['item_meta'];
  10.       $product_ids = $item_metas['_product_id'];
  11.       foreach ($product_ids as $product_id) {
  12.         switch ($product_id) {
  13.           case 1:
  14.             break;
  15.           case 2:
  16.             break;
  17.           default:
  18.         }
  19.         echo '<p>'.$item['name'].' '.$product_id.'</p>';
  20.       }
  21.     }
  22.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement