<tbody> <?php if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if (isset($item['variation_id']) && $item['variation_id'] > 0) { $_product = new WC_Product_Variation($item['variation_id']); } else { $_product = new WC_Product($item['id']); } echo ' <tr> <td class="product-name">'; echo '<a href="' . get_permalink($item['id']) . '">' . $item['name'] . '</a>'; $item_meta = new order_item_meta($item['item_meta']); $item_meta->display(); if ($_product->exists && $_product->is_downloadable() && ($order->status == 'completed' || get_option('woocommerce_downloads_grant_access_after_payment') == 'yes' && $order->status == 'processing')) { echo '<br/><small><a href="' . $order->get_downloadable_file_url($item['id'], $item['variation_id']) . '">' . __('Download file →', 'woocommerce') . '</a></small>'; } echo '</td><td class="product-quantity">' . $item['qty'] . '</td><td class="product-total">' . $order->get_formatted_line_subtotal($item) . '</td></tr>'; // Show any purchase notes if ($order->status == 'completed' || $order->status == 'processing') { if ($purchase_note = get_post_meta($_product->id, '_purchase_note', true)) { echo '<tr class="product-purchase-note"><td colspan="3">' . apply_filters('the_content', $purchase_note) . '</td></tr>'; } } } } do_action('woocommerce_order_items_table', $order); ?> </tbody> </table>
/** * Get the downloads for a product or product variation * * @since 2.1 * @param WC_Product|WC_Product_Variation $product * @return array */ private function get_downloads($product) { $downloads = array(); if ($product->is_downloadable()) { foreach ($product->get_files() as $file_id => $file) { $downloads[] = array('id' => $file_id, 'name' => $file['name'], 'file' => $file['file']); } } return $downloads; }
/** * Get product data. * * @param WC_Product $product Product instance. * @return array */ protected function get_product_data($product) { $data = array('id' => $product->get_id(), 'name' => $product->get_name(), 'slug' => $product->get_slug(), 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_date_created()), 'date_modified' => wc_rest_prepare_date_response($product->get_date_modified()), 'type' => $product->get_type(), 'status' => $product->get_status(), 'featured' => $product->is_featured(), 'catalog_visibility' => $product->get_catalog_visibility(), 'description' => wpautop(do_shortcode($product->get_description())), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '', 'date_on_sale_from' => $product->get_date_on_sale_from() ? date('Y-m-d', $product->get_date_on_sale_from()) : '', 'date_on_sale_to' => $product->get_date_on_sale_to() ? date('Y-m-d', $product->get_date_on_sale_to()) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => $product->get_total_sales(), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'external_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'manage_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders' => $product->get_backorders(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'weight' => $product->get_weight(), 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height()), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => $product->get_shipping_class_id(), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'parent_id' => $product->get_parent_id(), 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->get_purchase_note()))), 'categories' => $this->get_taxonomy_terms($product), 'tags' => $this->get_taxonomy_terms($product, 'tag'), 'images' => $this->get_images($product), 'attributes' => $this->get_attributes($product), 'default_attributes' => $this->get_default_attributes($product), 'variations' => array(), 'grouped_products' => array(), 'menu_order' => $product->get_menu_order()); return $data; }
function woocommerce_custom_product_columns($column) { global $post, $woocommerce; $product = new WC_Product($post->ID); switch ($column) { case "thumb": $product->get_image(); break; case "name": $edit_link = get_edit_post_link($post->ID); $title = _draft_or_post_title(); $post_type_object = get_post_type_object($post->post_type); $can_edit_post = current_user_can($post_type_object->cap->edit_post, $post->ID); echo '<strong><a class="row-title" href="' . $edit_link . '">' . $title . '</a>'; _post_states($post); echo '</strong>'; if ($post->post_parent > 0) { echo ' ← <a href="' . get_edit_post_link($post->post_parent) . '">' . get_the_title($post->post_parent) . '</a>'; } // Excerpt view if (isset($_GET['mode']) && $_GET['mode'] == 'excerpt') { echo apply_filters('the_excerpt', $post->post_excerpt); } // Get actions $actions = array(); $actions['id'] = 'ID: ' . $post->ID; if ($can_edit_post && 'trash' != $post->post_status) { $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this item inline', 'woocommerce')) . '">' . __('Quick Edit', 'woocommerce') . '</a>'; } if (current_user_can($post_type_object->cap->delete_post, $post->ID)) { if ('trash' == $post->post_status) { $actions['untrash'] = "<a title='" . esc_attr(__('Restore this item from the Trash', 'woocommerce')) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $post->ID)), 'untrash-' . $post->post_type . '_' . $post->ID) . "'>" . __('Restore', 'woocommerce') . "</a>"; } elseif (EMPTY_TRASH_DAYS) { $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this item to the Trash', 'woocommerce')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash', 'woocommerce') . "</a>"; } if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) { $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this item permanently', 'woocommerce')) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently', 'woocommerce') . "</a>"; } } if ($post_type_object->public) { if (in_array($post->post_status, array('pending', 'draft'))) { if ($can_edit_post) { $actions['view'] = '<a href="' . esc_url(add_query_arg('preview', 'true', get_permalink($post->ID))) . '" title="' . esc_attr(sprintf(__('Preview “%s”', 'woocommerce'), $title)) . '" rel="permalink">' . __('Preview', 'woocommerce') . '</a>'; } } elseif ('trash' != $post->post_status) { $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View “%s”', 'woocommerce'), $title)) . '" rel="permalink">' . __('View', 'woocommerce') . '</a>'; } } $actions = apply_filters('post_row_actions', $actions, $post); echo '<div class="row-actions">'; $i = 0; $action_count = sizeof($actions); foreach ($actions as $action => $link) { ++$i; $i == $action_count ? $sep = '' : ($sep = ' | '); echo "<span class='{$action}'>{$link}{$sep}</span>"; } echo '</div>'; get_inline_data($post); /* Custom inline data for woocommerce */ echo ' <div class="hidden" id="woocommerce_inline_' . $post->ID . '"> <div class="sku">' . $product->sku . '</div> <div class="regular_price">' . $product->regular_price . '</div> <div class="sale_price">' . $product->sale_price . '</div> <div class="weight">' . $product->weight . '</div> <div class="length">' . $product->length . '</div> <div class="width">' . $product->width . '</div> <div class="height">' . $product->height . '</div> <div class="visibility">' . $product->visibility . '</div> <div class="stock_status">' . $product->stock_status . '</div> <div class="stock">' . $product->stock . '</div> <div class="manage_stock">' . $product->manage_stock . '</div> <div class="featured">' . $product->featured . '</div> <div class="product_type">' . $product->product_type . '</div> <div class="product_is_virtual">' . $product->virtual . '</div> </div> '; break; case "sku": if ($product->get_sku()) { echo $product->get_sku(); } else { echo '<span class="na">–</span>'; } break; case "product_type": if ($product->product_type == 'grouped') { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Grouped', 'woocommerce') . '"></span>'; } elseif ($product->product_type == 'external') { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('External/Affiliate', 'woocommerce') . '"></span>'; } elseif ($product->product_type == 'simple') { if ($product->is_virtual()) { echo '<span class="product-type tips virtual" tip="' . __('Virtual', 'woocommerce') . '"></span>'; } elseif ($product->is_downloadable()) { echo '<span class="product-type tips downloadable" tip="' . __('Downloadable', 'woocommerce') . '"></span>'; } else { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Simple', 'woocommerce') . '"></span>'; } } elseif ($product->product_type == 'variable') { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Variable', 'woocommerce') . '"></span>'; } else { // Assuming that we have other types in future echo '<span class="product-type tips ' . $product->product_type . '" tip="' . ucwords($product->product_type) . '"></span>'; } break; case "price": if ($product->get_price_html()) { echo $product->get_price_html(); } else { echo '<span class="na">–</span>'; } break; case "product_cat": if (!($terms = get_the_term_list($post->ID, 'product_cat', '', ', ', ''))) { echo '<span class="na">–</span>'; } else { echo $terms; } break; case "product_tags": if (!($terms = get_the_term_list($post->ID, 'product_tag', '', ', ', ''))) { echo '<span class="na">–</span>'; } else { echo $terms; } break; case "featured": $url = wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-feature-product&product_id=' . $post->ID), 'woocommerce-feature-product'); echo '<a href="' . $url . '" title="' . __('Change', 'woocommerce') . '">'; if ($product->is_featured()) { echo '<a href="' . $url . '"><img src="' . $woocommerce->plugin_url() . '/assets/images/featured.png" alt="yes" />'; } else { echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/featured-off.png" alt="no" />'; } echo '</a>'; break; case "is_in_stock": if ($product->is_in_stock()) { echo '<mark class="instock">' . __('In stock', 'woocommerce') . '</mark>'; } else { echo '<mark class="outofstock">' . __('Out of stock', 'woocommerce') . '</mark>'; } if ($product->managing_stock()) { echo ' × ' . $product->get_total_stock(); } break; } }
$variation_id = mysql_real_escape_string($_POST['variationid']); if ($variation_id == 'undefined') { $variation_id = ''; } if (!empty($variation_id)) { $variation = new WC_Product_Variation($variation_id); $productPrice = $variation->get_price(); } // If user has required ammount of credits then continue if ($getUserCredit >= $productPrice) { get_currentuserinfo(); // Save the purchase to the database and update credits balance of the user $sql = $wpdb->query("UPDATE `" . $wpdb->prefix . "woocredit_users` SET credit = '" . ($getUserCredit - $productPrice) . "' where user_id=" . get_current_user_id()); $sql = $wpdb->query("INSERT INTO `" . $wpdb->prefix . "woocredit_products` (user_id, product_id, price) VALUES (" . get_current_user_id() . "," . $_POST['productid'] . "," . $productPrice . ")"); // If the product or variant are downloadable then send an email with a link to the files if ($product && $product->is_downloadable() || $variation && $variation->is_downloadable()) { $files = []; if ($product && $product->is_downloadable()) { $files = $product->get_files(); } if ($variation && $variation->is_downloadable()) { $files = $variation->get_files(); } $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $codingKey = $translate->getCodingKey(); $downloadHtml = ""; foreach ($files as $file) { $downloadHtml .= '<a href="'; $downloadHtml .= get_site_url() . "/wp-content/plugins/simple-credits/download.php?action=email"; $downloadHtml .= "&time=" . $translate->encode(time(), $codingKey);
?> <?php foreach ($order_summary as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $needs_shipping = false; $items = $order->get_items(); foreach ($items as $key => $value) { if (in_array($value['variation_id'], $valid_items) || in_array($value['product_id'], $valid_items)) { $valid[] = $value; } // See if product needs shipping $product = new WC_Product($value['product_id']); $needs_shipping = !$product->needs_shipping() || $product->is_downloadable('yes') ? false : true; } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers); ?> <tr> <td><?php echo $order->get_order_number(); ?> </td> <td><?php echo apply_filters('wcvendors_dashboard_google_maps_link', '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode(esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address()))) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address())) . '</a>'); ?> </td> <td><?php
</tfoot> <tbody> <?php if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if (isset($item['variation_id']) && $item['variation_id'] > 0) { $_product = new WC_Product_Variation($item['variation_id']); } else { $_product = new WC_Product($item['id']); } echo ' <tr> <td class="product-name">' . $item['name']; $item_meta = new order_item_meta($item['item_meta']); $item_meta->display(); if ($_product->exists && $_product->is_downloadable() && $order->status == 'completed') { echo '<br/><small><a href="' . $order->get_downloadable_file_url($item['id'], $item['variation_id']) . '">' . __('Download file →', 'woocommerce') . '</a></small>'; } echo '</td><td class="product-quantity">' . $item['qty'] . '</td><td class="product-total">' . $order->get_formatted_line_subtotal($item) . '</td></tr>'; } } do_action('woocommerce_order_items_table', $order); ?> </tbody> </table> <header> <h2><?php _e('Customer details', 'woocommerce'); ?> </h2>
/** * Add a product to the cart * * @param string product_id contains the id of the product to add to the cart * @param string quantity contains the quantity of the item to add * @param int variation_id * @param array variation attribute values */ function add_to_cart($product_id, $quantity = 1, $variation_id = '', $variation = '', $cart_item_data = array()) { global $woocommerce; if ($quantity < 1) { return false; } // Load cart item data - may be added by other plugins $cart_item_data = (array) apply_filters('woocommerce_add_cart_item_data', $cart_item_data, $product_id); // Generate a ID based on product ID, variation ID, variation data, and other cart item data $cart_id = $this->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data); // See if this product and its options is already in the cart $cart_item_key = $this->find_product_in_cart($cart_id); if ($variation_id > 0) { $product_data = new WC_Product_Variation($variation_id); } else { $product_data = new WC_Product($product_id); } // Type/Exists check if ($product_data->is_type('external') || !$product_data->exists()) { $woocommerce->add_error(__('This product cannot be purchased.', 'woocommerce')); return false; } // Price set check if ($product_data->get_price() === '') { $woocommerce->add_error(__('This product cannot be purchased - the price is not yet set.', 'woocommerce')); return false; } // Stock check - only check if we're managing stock and backorders are not allowed if (!$product_data->has_enough_stock($quantity)) { $woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock. We have %s in stock.', 'woocommerce'), $product_data->get_stock_quantity())); return false; } elseif (!$product_data->is_in_stock()) { $woocommerce->add_error(__('You cannot add that product to the cart since the product is out of stock.', 'woocommerce')); return false; } // Downloadable/virtual qty check if (get_option('woocommerce_limit_downloadable_product_qty') == 'yes' && $product_data->is_downloadable() && $product_data->is_virtual()) { $qty = $cart_item_key ? $this->cart_contents[$cart_item_key]['quantity'] + $quantity : $quantity; if ($qty > 1) { $woocommerce->add_error(__('You already have this item in your cart.', 'woocommerce')); return false; } } if ($cart_item_key) { $quantity = $quantity + $this->cart_contents[$cart_item_key]['quantity']; // Stock check - this time accounting for whats already in-cart if (!$product_data->has_enough_stock($quantity)) { $woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock. We have %s in stock and you already have %s in your cart.', 'woocommerce'), $product_data->get_stock_quantity(), $this->cart_contents[$cart_item_key]['quantity'])); return false; } elseif (!$product_data->is_in_stock()) { $woocommerce->add_error(__('You cannot add that product to the cart since the product is out of stock.', 'woocommerce')); return false; } $this->set_quantity($cart_item_key, $quantity); } else { // Add item after merging with $cart_item_data - hook to allow plugins to modify cart item $this->cart_contents[$cart_id] = apply_filters('woocommerce_add_cart_item', array_merge($cart_item_data, array('product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data))); } $woocommerce->cart_has_contents_cookie(true); $this->set_session(); return true; }
/** * Returns the voucher attached to $product * * @since 1.2 * @param WC_Product $product the voucher product * @return WC_Voucher the voucher attached to $product */ public static function get_voucher($product) { if ($product->is_type('variable')) { foreach ($product->get_children() as $variation_product_id) { $variation_product = wc_get_product($variation_product_id); if ($variation_product->is_downloadable() && $variation_product->voucher_id) { // Note: this assumes that there is only one voucher attached to any variations for a product, which probably isn't a great assumption, but simplifies the frontend for now return new WC_Voucher($variation_product->voucher_id); } } } elseif ($product->is_downloadable() && $product->voucher_id) { // simple product or product variation return new WC_Voucher($product->voucher_id); } // aw, no voucher return null; }