get_item_data() 공개 메소드

Gets and formats a list of cart item data + variations for display on the frontend.
public get_item_data ( array $cart_item, boolean $flat = false ) : string
$cart_item array
$flat boolean (default: false)
리턴 string
 /**
  *
  */
 public function filter_woocommerce_add_to_cart_validation($valid, $product_id, $quantity, $variation_id = '', $variations = '')
 {
     global $woocommerce;
     $product = wc_get_product($product_id);
     if ($product->product_type === "variable") {
         $deductornot = get_post_meta($variation_id, '_deductornot', true);
         $deductamount = get_post_meta($variation_id, '_deductamount', true);
         $getvarclass = new WC_Product_Variation($variation_id);
         //reset($array);
         $aatrs = $getvarclass->get_variation_attributes();
         foreach ($aatrs as $key => $value) {
             $slug = $value;
             $cat = str_replace('attribute_', '', $key);
         }
         $titlevaria = get_term_by('slug', $slug, $cat);
         $backorder = get_post_meta($product->post->ID, '_backorders', true);
         $string = WC_Cart::get_item_data($cart_item, $flat);
         //var_dump($string);
         if ($backorder == 'no') {
             if ($deductornot == "yes") {
                 $currentstock = $product->get_stock_quantity();
                 $reduceamount = intval($quantity) * intval($deductamount);
                 $currentavail = intval($currentstock / $deductamount);
                 if ($reduceamount > $currentstock) {
                     $valid = false;
                     wc_add_notice('' . __('You that goes over our availble stock amount.', 'woocommerce') . __('We have: ', 'woocommerce') . $currentavail . ' ' . $product->post->post_title . ' ' . $titlevaria->name . '\'s ' . __(' available.', 'woocommerce'), 'error');
                     return $valid;
                 } else {
                     $valid = true;
                     return $valid;
                 }
             } else {
                 return true;
             }
         }
     }
     return true;
 }
 function display_order_shipping_addresses($order)
 {
     global $woocommerce;
     $order_id = $order->id;
     $addresses = get_post_meta($order_id, '_shipping_addresses', true);
     $methods = get_post_meta($order_id, '_shipping_methods', true);
     $packages = get_post_meta($order_id, '_wcms_packages', true);
     $items = $order->get_items();
     $available_methods = $woocommerce->shipping->load_shipping_methods();
     //if (empty($addresses)) return;
     if (!$packages || count($packages) == 1) {
         return;
     }
     // load the address fields
     $this->load_cart_files();
     $checkout = new WC_Checkout();
     $cart = new WC_Cart();
     $shipFields = $woocommerce->countries->get_address_fields($woocommerce->countries->get_base_country(), 'shipping_');
     echo '<p><strong>' . __('This order ships to multiple addresses.', 'wc_shipping_multiple_address') . '</strong></p>';
     echo '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">';
     echo '<thead><tr>';
     echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Product', 'woocommerce') . '</th>';
     echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Qty', 'woocommerce') . '</th>';
     echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('', 'woocommerce') . '</th>';
     echo '</thead><tbody>';
     foreach ($packages as $x => $package) {
         $products = $package['contents'];
         $method = $methods[$x]['label'];
         foreach ($available_methods as $ship_method) {
             if ($ship_method->id == $method) {
                 $method = $ship_method->get_title();
                 break;
             }
         }
         $address = isset($package['full_address']) && !empty($package['full_address']) ? $woocommerce->countries->get_formatted_address($package['full_address']) : '';
         foreach ($products as $i => $product) {
             echo '<tr>';
             echo '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . get_the_title($product['data']->id) . '<br />' . $cart->get_item_data($product, true) . '</td>';
             echo '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $product['quantity'] . '</td>';
             echo '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $address . '<br/><em>( ' . $method . ' )</em></td>';
             echo '</tr>';
         }
     }
     echo '</table>';
 }
        function list_order_item_addresses($order_id)
        {
            global $woocommerce;
            if (false == apply_filters('wcms_list_order_item_addresses', true, $order_id)) {
                return;
            }
            if ($order_id instanceof WC_Order) {
                $order = $order_id;
                $order_id = $order->id;
            } else {
                $order = WC_MS_Compatibility::wc_get_order($order_id);
            }
            $methods = get_post_meta($order_id, '_shipping_methods', true);
            $shipping_methods = $order->get_shipping_methods();
            $packages = get_post_meta($order_id, '_wcms_packages', true);
            $multiship = get_post_meta($order_id, '_multiple_shipping', true);
            if (!$packages || count($packages) == 1) {
                return;
            }
            // load the address fields
            $this->load_cart_files();
            $cart = new WC_Cart();
            echo '<p><strong>' . __('This order ships to multiple addresses.', 'wc_shipping_multiple_address') . '</strong></p>';
            echo '<table class="shop_table shipping_packages" cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">';
            echo '<thead><tr>';
            echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Products', 'woocommerce') . '</th>';
            echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Address', 'woocommerce') . '</th>';
            echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Notes', 'woocommerce') . '</th>';
            echo '</tr></thead><tbody>';
            foreach ($packages as $x => $package) {
                $products = $package['contents'];
                $method = $methods[$x]['label'];
                foreach ($shipping_methods as $ship_method) {
                    if ($ship_method['method_id'] == $method) {
                        $method = $ship_method['name'];
                        break;
                    }
                }
                $address = '';
                if (!empty($package['full_address'])) {
                    $address = wcms_get_formatted_address($package['full_address']);
                }
                ?>
                <tr>
                    <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><ul>
                    <?php 
                foreach ($products as $i => $product) {
                    ?>
                        <li><?php 
                    echo get_the_title($product['data']->id) . ' &times; ' . $product['quantity'] . '<br />' . $cart->get_item_data($product, true);
                    ?>
</li>
                    <?php 
                }
                ?>
                    </ul></td>
                    <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">
                        <?php 
                echo $address;
                ?>
                        <br/>
                        <em>(<?php 
                echo $method;
                ?>
)</em>
                    </td>
                    <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">
                        <?php 
                if (!empty($package['note'])) {
                    echo $package['note'];
                } else {
                    echo '&ndash;';
                }
                if (!empty($package['date'])) {
                    echo '<p>' . sprintf(__('Delivery date: %s', 'wc_shipping_multiple_address'), $package['date']) . '</p>';
                }
                ?>
                    </td>
                </tr>
                <?php 
            }
            echo '</table>';
        }
</th>
                        <th scope="col" style="text-align:left; width: 15%;"><?php 
        _e('Quantity', 'woocommerce-pip');
        ?>
</th>
                        <th scope="col" style="text-align:left; width: 20%;"><?php 
        _e('Total Weight', 'woocommerce-pip');
        ?>
</th>
                    </tr>
                    </thead>
                        <tbody>
                        <?php 
        $cart = new WC_Cart();
        foreach ($package['contents'] as $item_key => $item) {
            $attributes = $cart->get_item_data($item, true);
            // get the product; if this variation or product has been deleted, this will return null...
            $_product = $order->get_product_from_item($item);
            $sku = $variation = '';
            if ($_product) {
                $sku = $_product->get_sku();
            }
            if (!empty($attributes)) {
                $variation = '<small style="display: block; margin: 5px 0 10px 10px;">' . str_replace("\n", "<br/>", $attributes) . '</small>';
            }
            ?>
                            <tr>
                            <td style="text-align:left; padding: 3px;"><?php 
            echo $sku;
            ?>
</td>