Woocommerce හෙල්ප්

oxide

Well-known member
  • Jan 30, 2012
    2,259
    1,239
    113
    මේකෙ
    මචංලා..woocommerce variable product එකක , එක එක variation එකට අදාල Sold count එක ගන්න විදියක් කියපල්ලකො... :rolleyes: :rolleyes:
     

    aquaman2020

    Well-known member
  • Dec 23, 2020
    1,395
    1,761
    113
    Bangkok
    PHP:
    <?php
    global $woocommerce, $nasa_opt, $product, $post, $wpdb;
    date_default_timezone_set("Asia/Bangkok");
    $date_from = date('Y-m-d h:i:s', strtotime('-30 days'));
    $date_to = date('Y-m-d h:i:s');
    $pro = array();
    $u_orders = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ('wc-processing','wc-completed') AND post_date BETWEEN '{$date_from}' AND '{$date_to}' ");
    if($u_orders && $u_orders != null && (is_object($u_orders) || is_array($u_orders))) {
        foreach($u_orders as $u_order){
            $order = null; $orderId = null;
            $order = new WC_Order($u_order->ID);
            if($order) {
                foreach ($order->get_items() as $item_id => $item ) {
                    $itID = 0;
                    $itID = (int)$item['product_id'];
                    if($itID > 0) {
                        if($pro[$itID] == null || $pro[$itID] == 'undefined' || empty($pro[$itID]) || is_nan($pro[$itID]) || $pro[$itID] == '' || $pro[$itID] == 0) {
                            $pro[$itID] = (int) $item->get_quantity();
                        } else {
                            $pro[$itID] = ((int) $pro[$itID] + (int) $item->get_quantity());
                        }  
                    }                                    
                }                              
            }
        }
    }
    ?>

    $item['product_id'] මේක වෙනස් කරපන් var id එකට

    date range එක ඕන නැත්තම් අයින් කරපන්
     

    oxide

    Well-known member
  • Jan 30, 2012
    2,259
    1,239
    113
    මේකෙ
    PHP:
    <?php
    global $woocommerce, $nasa_opt, $product, $post, $wpdb;
    date_default_timezone_set("Asia/Bangkok");
    $date_from = date('Y-m-d h:i:s', strtotime('-30 days'));
    $date_to = date('Y-m-d h:i:s');
    $pro = array();
    $u_orders = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ('wc-processing','wc-completed') AND post_date BETWEEN '{$date_from}' AND '{$date_to}' ");
    if($u_orders && $u_orders != null && (is_object($u_orders) || is_array($u_orders))) {
        foreach($u_orders as $u_order){
            $order = null; $orderId = null;
            $order = new WC_Order($u_order->ID);
            if($order) {
                foreach ($order->get_items() as $item_id => $item ) {
                    $itID = 0;
                    $itID = (int)$item['product_id'];
                    if($itID > 0) {
                        if($pro[$itID] == null || $pro[$itID] == 'undefined' || empty($pro[$itID]) || is_nan($pro[$itID]) || $pro[$itID] == '' || $pro[$itID] == 0) {
                            $pro[$itID] = (int) $item->get_quantity();
                        } else {
                            $pro[$itID] = ((int) $pro[$itID] + (int) $item->get_quantity());
                        }
                    }                                  
                }                            
            }
        }
    }
    ?>

    $item['product_id'] මේක වෙනස් කරපන් var id එකට

    date range එක ඕන නැත්තම් අයින් කරපන්
    මචං..මට ඕනා සම්පූර්ණ ප්‍රඩක්ට් එකේ සෝල්ඩ් උන අයිටම් කවුන්ට් එක නෙවෙයි.. එක එක වේරියේෂන් එකෙන් සෝල්ඩ් උන කවුන්ට් එක..
    ප:ලි

    එල එල කරල බලන්නම්..ටෑම්ස් මචං...