Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #2468034
Custom Post Type
Closed

Comments

  •  10
    Shelley started the conversation

    On the thank you page I am trying to do a quantity count on a custom woocommerce thank you page for the custom pinterest ads tracking.

    I have written some PHP code to count the quantity but it counts bundles with an extra count.

    i.e. Bundle of 2 products is quantity 3 - 2 for the individual items and 1 for the bundle.  I need to basically do 


    Total Quantity - # of bundles = Quantity of items sold


    Any idea how to count up if the bundle is present? Or at least what is the name of your custom post type - is it just 'bundle' ?

    This is what I have thus far:


    $sumofitems = 0;
    foreach ( $order->get_items() as $item_id => $item ) {

     
       $quantity = $item->get_quantity();
       $sumofitems+=$quantity;
      
      
      
      
      
    }

       



    ?> 
            <script>
      


      pintrk('track', 'checkout', {  
            order_id: '<?php  echo  $order_id_number ?>',
    value: '<?php echo $totalamount ?>', 
            order_quantity: '<?php echo  $sumofitems ?>',
            currency: 'USD',
    em: '<?php echo wp_get_current_user()->user_email ?>'


      });




  •  767
    Janilyn replied

    Hi Shelley,

    Thank you for contacting WPClever Support Forum. 

    We’ve received your ticket and assigned one of our developers to help you with that. 

    He’ll be looking into your question and responding with specific instructions as soon as possible. 

    Please stay patient since we're having very heavy workloads at the moment. 

    Best regards.

    Janilyn T. - WPClever Support Agent

  •  1,227
    Dustin replied

    Hi Shelley,

    I'm so sorry for the late reply!

    In the loop:

    foreach ( $order->get_items() as $item_id => $item ) {}

    You can count the bundles or bundled products by using the code below:

    $bundles = $bundled = 0;
    foreach ( $order->get_items() as $item_id => $item ) {
        if ( $item->get_meta( '_woosb_parent_id' ) ) {
            // count bundled products
            $bundled += $item->get_quantity();
        }
        if ( $order_item->get_meta( '_woosb_ids' ) ) {
            // count bundles
            $bundles += $item->get_quantity();
        }
    }
    

    Best regards,
    Dustin