• Hi! I am working on writing code for the Pinterest tag. I need to count the number of product bundles in the order (on the thank you page). Can you help with that expression?

    Basically b/c the order quantity for a bundle of two products is three, I need to subtract 1 from the total quantity which I have already calculated with this code:

    add_action('wp_head', 'wpb_hook_javascript1'); // Adds this to the head
    
    function wpb_hook_javascript1() {
      if (is_page ( array('1751'))) { //Adds it to the specific page, in this case WooCommerce cart
    
    	
    // This calls the cart contents
    
    $order_id_number = wc_get_order_id_by_order_key( $_GET['key'] );
    $order = wc_get_order( $order_id_number );
    $totalamount = $order->get_total();
    	
    $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 ?>'
    			
    			
      });
    </script>
  • The topic ‘Code to check how many bundles are in an order’ is closed to new replies.