• Hi,
    I want some a code which will execute on thankyou page template when some fix defined product buy. like when I buy product id=1 then only special message come “You are Lucky”. Otherwise no special message.
    How to do this?please help me….

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Use the hooks available on that end-point to create conditional messages. If you’re unsure which hooks are fired on that end-point, have a look at the excellent https://hookr.io/plugin plugin.

    Suggest not changing the page template if it can be avoided. Try something like this in functions.php for your child theme:

    
    <?php
      // woocommerce_thankyou hook
      // code goes in functions.php for child theme
      add_action ('woocommerce_thankyou', 'myfunction');
      function myfunction($order_id) {
        $order = new WC_Order($order_id);
        $items = $order->get_items();
        foreach ($items as $item) {
          $item_metas = $item['item_meta'];
          $product_ids = $item_metas['_product_id'];
          foreach ($product_ids as $product_id) {
            if ($product_id == 1) {
              echo '<p>You are lucky!</p>';
              break;
            }      
          }
        }
      }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If Specific Product by id sold then custom message on thank you page code’ is closed to new replies.