Untitled
raw download clone
TEXT
views 27
,
size 3618 b
ob_start();
get_header();
?>


<div class="container">


    <?php
    global $woocommerce, $post, $wpdb;
    date_default_timezone_set('Europe/Warsaw');
    $czas_dokumentu = date('m/d/Y H:i:s', time());

    $datetime1 = new DateTimeImmutable('last friday 12:00:00');
    $datetime2 = $datetime1->modify('+ 1 week');



    $sql_active_vendors = 'SELECT DISTINCT user_id, vendor_id, user_email, name from wp_yith_vendors_commissions
            join wp_users on wp_yith_vendors_commissions.user_id = wp_users.id
            join wp_terms on wp_yith_vendors_commissions.vendor_id = wp_terms.term_id';
    $active_vendors = $wpdb->get_results($sql_active_vendors);

    foreach ($active_vendors as $query2) {

        $vendor_id = $query2->vendor_id;
        $vendor_mail = $query2->user_email;
        $vendor_name = $query2->name;

        echo '<h2>'.$vendor_name . ' ' . $vendor_mail.'</h2>';
        $sql3 = 'SELECT DISTINCT wp_yith_vendors_commissions.order_id, date_created from wp_yith_vendors_commissions
            join wp_wc_order_product_lookup on wp_yith_vendors_commissions.order_id = wp_wc_order_product_lookup.order_id where vendor_id="' . $vendor_id . '"
            AND date_created BETWEEN 
            "' . $datetime1->format("Y-m-d H:i:s") . '"
            AND
            "' . $datetime2->format("Y-m-d H:i:s") . '"
            ';

        $order_id = $wpdb->get_results($sql3);
        if (count($order_id) > 0) {
            foreach ($order_id as $order_ids) {
                //echo '</br>' . $vendor_id . ' ' . $vendor_mail . ' ' . $vendor_name . '</br>';

                $orderID = $order_ids->order_id;
                $order_date = $order_ids->date_created;
                $single_order = wc_get_order($orderID);
                echo '</br>';
                echo __('ID zamówienia: ') . $orderID . '<br>';
                echo __('Data zamówienia: ') . $order_date . '<br>';

                $product_quantity = array();
                $product_name = array();
                $single_order_array=array();
                $results=array();
                foreach ($single_order->get_items() as $item) {

                    echo __('Nazwa produktu: ') . $item->get_name() . '<br>';
                    echo __('Ilość: ') . $item->get_quantity() . '<br><br><br>';

                    $product_quantity = $item->get_quantity();
                    $product_name = $item->get_name();
                    $single_order_array[]=array($product_name => $product_quantity);
                }

                echo '</br>TABLICA POJEDYNCZEGO ZAMOWIENIA: </br>';
                print_r($single_order_array);
                echo '</br></br>';

                foreach ($single_order_array as $product=>$quantity){
                    if (array_key_exists($product, $results)){
                        $results[$product]+=$quantity;
                        echo '</br>TABLICA CAŁEGO WENDORA : </br>';
                        print_r($results);
                    }
                    else {
                        $results += array ($product=>$quantity);
                        echo '</br>TABLICA CAŁEGO WENDORA : </br>';
                        print_r($results);
                    }
                }
            }
            //echo '</br>TABLICA CAŁEGO WENDORA : </br>';
            //print_r($results);
            echo '</br></br>';
        } else {
            return;


        }
        ob_flush();
    } /*-- END MAIN FOREACH */


    ?>
</div>


<?php

get_footer(); ?>
close fullscreen
Login or Register to edit or fork this paste. It's free.