get_image() public method

Returns the main product image.
public get_image ( string $size = 'shop_thumbnail', array $attr = [], $placeholder = true ) : string
$size string (default: 'shop_thumbnail')
$attr array
return string
/**
 * Filter the document table row cells to add product thumbnail column data
 *
 * @param string $table_row_cells The table row cells.
 * @param string $type WC_PIP_Document type
 * @param string $item_id Item id
 * @param array $item Item data
 * @param \WC_Product $product Product object
 * @return array The filtered table row cells.
 */
function sv_wc_pip_document_table_row_cells_product_thumbnail($table_row_cells, $document_type, $item_id, $item, $product)
{
    // get the product's or variation's thumbnail 'shop_thumbnail' size; we will use CSS to set the width
    $thumbnail_content = array('product_thumbnail' => $product->get_image());
    // add product thumnail column as the first column
    return array_merge($thumbnail_content, $table_row_cells);
}
Example #2
0
    /**
     * widget function.
     *
     * @see WP_Widget
     * @access public
     * @param array $args
     * @param array $instance
     * @return void
     */
    function widget($args, $instance)
    {
        global $comments, $comment, $woocommerce;
        $cache = wp_cache_get('widget_recent_reviews', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Reviews', 'woocommerce') : $instance['title'], $instance, $this->id_base);
        if (!($number = absint($instance['number']))) {
            $number = 5;
        }
        $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product'));
        if ($comments) {
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            echo '<ul class="product_list_widget">';
            foreach ((array) $comments as $comment) {
                $_product = new WC_Product($comment->comment_post_ID);
                $star_size = apply_filters('woocommerce_star_rating_size_recent_reviews', 16);
                $rating = get_comment_meta($comment->comment_ID, 'rating', true);
                $rating_html = '<div class="star-rating" title="' . $rating . '">
					<span style="width:' . $rating * $star_size . 'px">' . $rating . ' ' . __('out of 5', 'woocommerce') . '</span>
				</div>';
                echo '<li><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">';
                echo $_product->get_image();
                echo $_product->get_title() . '</a>';
                echo $rating_html;
                printf(_x('by %1$s', 'by comment author', 'woocommerce'), get_comment_author()) . '</li>';
            }
            echo '</ul>';
            echo $after_widget;
        }
        $content = ob_get_clean();
        if (isset($args['widget_id'])) {
            $cache[$args['widget_id']] = $content;
        }
        echo $content;
        wp_cache_set('widget_recent_reviews', $cache, 'widget');
    }
 private function _getProductDetails($product_id)
 {
     $product = new WC_Product($product_id);
     ob_start();
     echo $product->get_image();
     $image = ob_get_clean();
     return array("item_name" => $product->get_title(), "item_description" => $product->post->post_content, "item_url" => $product->post->guid, "item_price" => $product->price, "item_picture_url" => $image);
 }
Example #4
0
/**
 * Order items meta box.
 *
 * Displays the order items meta box - for showing individual items in the order.
 */
function woocommerce_order_items_meta_box($post)
{
    global $woocommerce;
    $order_items = (array) maybe_unserialize(get_post_meta($post->ID, '_order_items', true));
    ?>
	<div class="woocommerce_order_items_wrapper">
		<table cellpadding="0" cellspacing="0" class="woocommerce_order_items">
			<thead>
				<tr>
					<th class="thumb" width="1%"><?php 
    _e('Item', 'woocommerce');
    ?>
</th>
					<th class="sku"><?php 
    _e('SKU', 'woocommerce');
    ?>
</th>
					<th class="name"><?php 
    _e('Name', 'woocommerce');
    ?>
</th>
					<?php 
    do_action('woocommerce_admin_order_item_headers');
    ?>

					<th class="tax_class"><?php 
    _e('Tax Class', 'woocommerce');
    ?>
&nbsp;<a class="tips" data-tip="<?php 
    _e('Tax class for the line item', 'woocommerce');
    ?>
." href="#">[?]</a></th>

					<th class="quantity"><?php 
    _e('Qty', 'woocommerce');
    ?>
</th>

					<th class="line_subtotal"><?php 
    _e('Line&nbsp;Subtotal', 'woocommerce');
    ?>
&nbsp;<a class="tips" data-tip="<?php 
    _e('Line cost and line tax before pre-tax discounts', 'woocommerce');
    ?>
" href="#">[?]</a></th>

					<th class="line_total"><?php 
    _e('Line&nbsp;Total', 'woocommerce');
    ?>
&nbsp;<a class="tips" data-tip="<?php 
    _e('Line cost and line tax after pre-tax discounts', 'woocommerce');
    ?>
" href="#">[?]</a></th>

				</tr>
			</thead>
			<tbody id="order_items_list">

				<?php 
    $loop = 0;
    if (sizeof($order_items) > 0 && isset($order_items[0]['id'])) {
        foreach ($order_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']);
            }
            // Totals - Backwards Compatibility
            if (!isset($item['line_total']) && isset($item['taxrate']) && isset($item['cost'])) {
                $item['line_tax'] = number_format($item['cost'] * $item['qty'] * ($item['taxrate'] / 100), 2, '.', '');
                $item['line_total'] = $item['cost'] * $item['qty'];
                $item['line_subtotal_tax'] = $item['line_tax'];
                $item['line_subtotal'] = $item['line_total'];
            }
            ?>
					<tr class="item" rel="<?php 
            echo $loop;
            ?>
">
						<td class="thumb">
							<a href="<?php 
            echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
            ?>
" class="tips" data-tip="<?php 
            echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $item['id'];
            echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ';
            if ($item['variation_id']) {
                echo $item['variation_id'];
            } else {
                echo '-';
            }
            echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ';
            if ($_product->sku) {
                echo $_product->sku;
            } else {
                echo '-';
            }
            ?>
"><?php 
            echo $_product->get_image();
            ?>
</a>
						</td>
						<td class="sku" width="1%">
							<?php 
            if ($_product->sku) {
                echo $_product->sku;
            } else {
                echo '-';
            }
            ?>
							<input type="hidden" class="item_id" name="item_id[<?php 
            echo $loop;
            ?>
]" value="<?php 
            echo esc_attr($item['id']);
            ?>
" />
							<input type="hidden" name="item_name[<?php 
            echo $loop;
            ?>
]" value="<?php 
            echo esc_attr($item['name']);
            ?>
" />
							<input type="hidden" name="item_variation[<?php 
            echo $loop;
            ?>
]" value="<?php 
            echo esc_attr($item['variation_id']);
            ?>
" />
						</td>
						<td class="name">

							<div class="row-actions">
								<span class="trash"><a class="remove_row" href="#"><?php 
            _e('Delete item', 'woocommerce');
            ?>
</a> | </span>
								<span class="view"><a href="<?php 
            echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
            ?>
"><?php 
            _e('View product', 'woocommerce');
            ?>
</a>
							</div>

							<?php 
            echo $item['name'];
            ?>
							<?php 
            if (isset($_product->variation_data)) {
                echo '<br/>' . woocommerce_get_formatted_variation($_product->variation_data, true);
            }
            ?>
							<table class="meta" cellspacing="0">
								<tfoot>
									<tr>
										<td colspan="4"><button class="add_meta button"><?php 
            _e('Add&nbsp;meta', 'woocommerce');
            ?>
</button></td>
									</tr>
								</tfoot>
								<tbody class="meta_items">
								<?php 
            if (isset($item['item_meta']) && is_array($item['item_meta']) && sizeof($item['item_meta']) > 0) {
                foreach ($item['item_meta'] as $key => $meta) {
                    // Backwards compatibility
                    if (is_array($meta) && isset($meta['meta_name'])) {
                        $meta_name = $meta['meta_name'];
                        $meta_value = $meta['meta_value'];
                    } else {
                        $meta_name = $key;
                        $meta_value = $meta;
                    }
                    echo '<tr><td><input type="text" name="meta_name[' . $loop . '][]" value="' . esc_attr($meta_name) . '" /></td><td><input type="text" name="meta_value[' . $loop . '][]" value="' . esc_attr($meta_value) . '" /></td><td width="1%"><button class="remove_meta button">&times;</button></td></tr>';
                }
            }
            ?>
								</tbody>
							</table>
						</td>

						<?php 
            do_action('woocommerce_admin_order_item_values', $_product, $item);
            ?>

						<td class="tax_class" width="1%">
							<select class="tax_class" name="item_tax_class[<?php 
            echo $loop;
            ?>
]" title="<?php 
            _e('Tax class', 'woocommerce');
            ?>
">
								<?php 
            $item_value = isset($item['tax_class']) ? sanitize_title($item['tax_class']) : '';
            $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes'))));
            $classes_options = array();
            $classes_options[''] = __('Standard', 'woocommerce');
            if ($tax_classes) {
                foreach ($tax_classes as $class) {
                    $classes_options[sanitize_title($class)] = $class;
                }
            }
            foreach ($classes_options as $value => $name) {
                echo '<option value="' . $value . '" ' . selected($value, $item_value, false) . '>' . $name . '</option>';
            }
            ?>
							</select>
						</td>

						<td class="quantity" width="1%">
							<input type="text" name="item_quantity[<?php 
            echo $loop;
            ?>
]" placeholder="0" value="<?php 
            echo esc_attr($item['qty']);
            ?>
" size="2" class="quantity" />
						</td>

						<td class="line_subtotal" width="1%">
							<label><?php 
            _e('Cost', 'woocommerce');
            ?>
: <input type="text" name="line_subtotal[<?php 
            echo $loop;
            ?>
]" placeholder="0.00" value="<?php 
            if (isset($item['line_subtotal'])) {
                echo esc_attr($item['line_subtotal']);
            }
            ?>
" class="line_subtotal" /></label>

							<label><?php 
            _e('Tax', 'woocommerce');
            ?>
: <input type="text" name="line_subtotal_tax[<?php 
            echo $loop;
            ?>
]" placeholder="0.00" value="<?php 
            if (isset($item['line_subtotal_tax'])) {
                echo esc_attr($item['line_subtotal_tax']);
            }
            ?>
" class="line_subtotal_tax" /></label>
						</td>

						<td class="line_total" width="1%">
							<label><?php 
            _e('Cost', 'woocommerce');
            ?>
: <input type="text" name="line_total[<?php 
            echo $loop;
            ?>
]" placeholder="0.00" value="<?php 
            if (isset($item['line_total'])) {
                echo esc_attr($item['line_total']);
            }
            ?>
" class="line_total" /></label>

							<label><?php 
            _e('Tax', 'woocommerce');
            ?>
: <input type="text" name="line_tax[<?php 
            echo $loop;
            ?>
]" placeholder="0.00" value="<?php 
            if (isset($item['line_tax'])) {
                echo esc_attr($item['line_tax']);
            }
            ?>
" class="line_tax" /></label>
						</td>

					</tr>
				<?php 
            $loop++;
        }
    }
    ?>
			</tbody>
		</table>
	</div>

	<p class="buttons">
		<select id="add_item_id" name="add_item_id[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php 
    _e('Search for a product&hellip;', 'woocommerce');
    ?>
" style="width: 400px"></select>

		<button type="button" class="button add_shop_order_item"><?php 
    _e('Add item(s)', 'woocommerce');
    ?>
</button>
	</p>
	<p class="buttons buttons-alt">
		<button type="button" class="button calc_line_taxes"><?php 
    _e('Calc line tax &uarr;', 'woocommerce');
    ?>
</button>
		<button type="button" class="button calc_totals"><?php 
    _e('Calc totals &rarr;', 'woocommerce');
    ?>
</button>
	</p>
	<div class="clear"></div>
	<?php 
}
Example #5
0
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 '&nbsp;&nbsp;&larr; <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&nbsp;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 . '&amp;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 &#8220;%s&#8221;', '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 &#8220;%s&#8221;', '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">&ndash;</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">&ndash;</span>';
            }
            break;
        case "product_cat":
            if (!($terms = get_the_term_list($post->ID, 'product_cat', '', ', ', ''))) {
                echo '<span class="na">&ndash;</span>';
            } else {
                echo $terms;
            }
            break;
        case "product_tags":
            if (!($terms = get_the_term_list($post->ID, 'product_tag', '', ', ', ''))) {
                echo '<span class="na">&ndash;</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 ' &times; ' . $product->get_total_stock();
            }
            break;
    }
}
Example #6
0
 private function update_product($body, $sku)
 {
     // hämta postid från sku
     $product = $this->get_product_by_sku($sku);
     // deleta alla attachments
     $okdelete = $this->delete_product_and_attachments($product->id, false);
     $args = array('ID' => $product->id, 'post_title' => $body['Item']['Description'], 'post_content' => $body['Item']['Content'], 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => 1, 'post_type' => 'product', 'post_name' => $sku, 'post_category' => array(0));
     // uppdatera posten
     $post_id = wp_update_post($args, true);
     $this->update_post_meta_product($product->sku, null, $product->id);
     if ($body['Item']['GrossPrice']) {
         $price = $body['Item']['GrossPrice'];
     }
     $this->setProductPrice($price > 0 ? $price : 666, $post_id);
     if (is_wp_error($post_id)) {
         $errors = $post_id->get_error_messages();
         foreach ($errors as $error) {
             echo $error;
         }
     }
     // inserta alla attachments och attribut och bilder
     $this->insert_attachment_product($body, $product->id, $product->sku);
     // sätt kategorin
     // om kategorin är satt i requesten
     if ($body['Item']['Category']) {
         $term = get_term_by('slug', $body['Item']['Category'], 'product_cat');
         // om kategorin/termen finns
         if ($term != false) {
             $ok = wp_set_object_terms($post_id, $term->term_id, 'product_cat');
         } else {
             $ok = wp_set_object_terms($post_id, 3377, 'product_cat');
         }
     }
     $post = new WC_Product($product->id);
     return array('post' => new WC_Product($post_id), 'attributes' => $post->get_attributes(), 'image' => $post->get_image(), 'Update' => true);
     return $post;
 }
Example #7
0
 private function get_product_from_post($post_id)
 {
     $woocommerce_ver_below_2_1 = false;
     if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) {
         $woocommerce_ver_below_2_1 = true;
     }
     if ($woocommerce_ver_below_2_1) {
         $product = new WC_Product_Simple($post_id);
     } else {
         $product = new WC_Product($post_id);
     }
     //$post_categories = wp_get_post_categories( $post_id );
     //$categories = get_the_category();
     try {
         $thumbnail = $product->get_image();
         if ($thumbnail) {
             if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                 $thumbnail = $match[1];
             } else {
                 if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) {
                     $thumbnail = $match[1];
                 } else {
                     if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                         // Animate Lazy Load Wordpress Plugin
                         $thumbnail = $match[1];
                     } else {
                         if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) {
                             $thumbnail = $match[1];
                         } else {
                             preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result);
                             $thumbnail = array_pop($result);
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in thumbnails";
         self::send_error_report($err_msg);
         $thumbnail = '';
     }
     // handling scheduled sale price update
     if (!$woocommerce_ver_below_2_1) {
         $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
         $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
         if ($sale_price_dates_from || $sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, null);
         }
         if ($sale_price_dates_from) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_from);
         }
         if ($sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_to);
         }
     }
     $product_tags = array();
     foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) {
         $product_tags[] = $tag->name;
     }
     $product_brands = array();
     if (taxonomy_exists('product_brand')) {
         foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) {
             $product_brands[] = $brand->name;
         }
     }
     $taxonomies = array();
     try {
         $all_taxonomies = get_option('wcis_taxonomies');
         if (is_array($all_taxonomies)) {
             foreach ($all_taxonomies as $taxonomy) {
                 if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) {
                     foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) {
                         if (!array_key_exists($taxonomy, $taxonomies)) {
                             $taxonomies[$taxonomy] = array();
                         }
                         $taxonomies[$taxonomy][] = $taxonomy_value->name;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $acf_fields = array();
     try {
         if (class_exists('acf') && function_exists('get_field')) {
             $all_acf_fields = get_option('wcis_acf_fields');
             if (is_array($all_acf_fields)) {
                 foreach ($all_acf_fields as $acf_field_name) {
                     $acf_field_value = get_field($acf_field_name, $post_id);
                     if ($acf_field_value) {
                         $acf_fields[$acf_field_name] = $acf_field_value;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
     try {
         $variable = new WC_Product_Variable($post_id);
         $variations = $variable->get_available_variations();
         $variations_sku = '';
         if (!empty($variations)) {
             foreach ($variations as $variation) {
                 if ($product->get_sku() != $variation['sku']) {
                     $variations_sku .= $variation['sku'] . ' ';
                 }
             }
         }
         $send_product['variations_sku'] = $variations_sku;
         $all_attributes = $product->get_attributes();
         $attributes = array();
         if (!empty($all_attributes)) {
             foreach ($all_attributes as $attr_mame => $value) {
                 if ($all_attributes[$attr_mame]['is_taxonomy']) {
                     if (!$woocommerce_ver_below_2_1) {
                         $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names'));
                     } else {
                         $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names');
                     }
                 } else {
                     $attributes[$attr_mame] = $product->get_attribute($attr_mame);
                 }
             }
         }
         $send_product['attributes'] = $attributes;
         $send_product['total_variable_stock'] = $variable->get_total_stock();
         try {
             if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
                 if (function_exists('wc_get_product')) {
                     $original_product = wc_get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             } else {
                 if (function_exists('get_product')) {
                     $original_product = get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             }
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in attributes";
         self::send_error_report($err_msg);
     }
     if (!$woocommerce_ver_below_2_1) {
         try {
             $send_product['price_compare_at_price'] = $product->get_regular_price();
             $send_product['price_min'] = $variable->get_variation_price('min');
             $send_product['price_max'] = $variable->get_variation_price('max');
             $send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min');
             $send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max');
         } catch (Exception $e) {
             $send_product['price_compare_at_price'] = null;
             $send_product['price_min'] = null;
             $send_product['price_max'] = null;
             $send_product['price_min_compare_at_price'] = null;
             $send_product['price_max_compare_at_price'] = null;
         }
     } else {
         $send_product['price_compare_at_price'] = null;
         $send_product['price_min'] = null;
         $send_product['price_max'] = null;
         $send_product['price_min_compare_at_price'] = null;
         $send_product['price_max_compare_at_price'] = null;
     }
     $send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']);
     $send_product['description'] = self::content_filter_shortcode($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']);
     try {
         if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) {
             if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
                 $language_info = apply_filters('wpml_post_language_details', NULL, $post_id);
             } else {
                 $language_info = wpml_get_language_information($post_id);
             }
             if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) {
                 // WP_Error could be returned from wpml_get_language_information(...)
                 $send_product['lang'] = $language_info['locale'];
             }
         }
     } catch (Exception $e) {
     }
     return $send_product;
 }
    public function woocommerce_cart_items_meta_box($post)
    {
        global $woocommerce;
        $order_items = (array) maybe_unserialize(get_post_meta($post->ID, 'av8_cartitems', true));
        ?>
	<div class="woocommerce_cart_reports_items_wrapper">
	<?php 
        if (sizeof($order_items) > 0) {
            ?>
		<table cellpadding="0" width="100%" cellspacing="0" class="woocommerce_cart_reports_items">
			<thead >
				<tr>
					<th class="thumb"  width="20%" style="text-align:left;"><?php 
            _e('Item', 'woocommerce');
            ?>
</th>

					<th class="sku"   width="20%" style="text-align:left"><?php 
            _e('SKU', 'woocommerce');
            ?>
</th>

					<th class="name"  width="20%" style="text-align:left"><?php 
            _e('Name', 'woocommerce');
            ?>
</th>

					<th class="price"  width="20%" style="text-align:left"><?php 
            _e('Price', 'woocommerce');
            ?>
</th>

					<?php 
            //do_action('woocommerce_admin_order_item_headers');
            ?>
					
					<th class="quantity"  width="20%" style="text-align:left"><?php 
            _e('Qty', 'woocommerce');
            ?>
</th>
										
				</tr>
			</thead>
			<tbody id="cart_items_list">	
			
			
				<?php 
        }
        $loop = 0;
        if (sizeof($order_items) > 0) {
            foreach ($order_items as $item) {
                if (isset($item['variation_id']) && $item['variation_id'] > 0) {
                    if (function_exists('get_product')) {
                        $_product = get_product($item['variation_id']);
                    } else {
                        $_product = new WC_Product($item['variation_id']);
                    }
                } else {
                    if (function_exists('get_product')) {
                        $_product = get_product($item['product_id']);
                    } else {
                        $_product = new WC_Product($item['product_id']);
                    }
                }
                // Totals - Backwards Compatibility
                if ($loop % 2 == 0) {
                    $table_color = " td1 ";
                } else {
                    $table_color = " td2 ";
                }
                ?>
					
					<?php 
                if (isset($_product) && $_product != false) {
                    ?>
					
					<tr class="item <?php 
                    echo $table_color;
                    ?>
" rel="<?php 
                    echo $loop;
                    ?>
">
						<td class="thumb" width="20%">
							<a href="<?php 
                    echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
                    ?>
" class="tips" data-tip="<?php 
                    echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $_product->id;
                    echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ';
                    if (isset($item->variation_id)) {
                        echo $item->variation_id;
                    } else {
                        echo '-';
                    }
                    echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ';
                    if (isset($_product->sku)) {
                        echo $_product->sku;
                    } else {
                        echo '-';
                    }
                    ?>
"><?php 
                    echo $_product->get_image();
                    ?>
</a>
						</td>
						<td class="sku" width="20%">
							<?php 
                    if ($_product->sku) {
                        echo $_product->sku;
                    } else {
                        echo '-';
                    }
                    ?>
							<input type="hidden" class="item_id" name="item_id[<?php 
                    echo $loop;
                    ?>
]" value="<?php 
                    if (isset($item->id) && $item->id != '') {
                        echo esc_attr($item->id);
                    }
                    ?>
" />
							<input type="hidden" name="item_name[<?php 
                    echo $loop;
                    ?>
]" value="<?php 
                    echo esc_attr($item->id);
                    ?>
" />
						<?php 
                    if (isset($item->variation_id)) {
                        ?>
	<input type="hidden" name="item_variation[<?php 
                        echo $loop;
                        ?>
]" value="<?php 
                        echo esc_attr($item->variation_id);
                        ?>
" /> <?php 
                    }
                    ?>
						</td>
						<td class="name" width="20%">
						
							<div class="row-actions">
								<span class="view"><a href="<?php 
                    echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
                    ?>
"><?php 
                    _e('View product', 'woocommerce');
                    ?>
</a>
							</div>
							
							<?php 
                    echo $_product->get_title();
                    ?>
							<?php 
                    if (isset($_product->variation_data)) {
                        echo '<br/>' . woocommerce_get_formatted_variation($_product->variation_data, true);
                    }
                    ?>

						</td>

						<?php 
                    //do_action('woocommerce_admin_order_item_values', $_product, $item);
                    ?>

						<td class="price"  width="20%"><p>
							<?php 
                    echo $_product->get_price_html();
                    ?>
						</p></td>
						
						<td class="quantity"  width="20%"><p>
							<?php 
                    echo $item['quantity'];
                    ?>
						</p></td>

						
					</tr>
					
					<?php 
                }
                ?>
				<?php 
                $loop++;
            }
        } else {
            //Explain to the user why no products could show up in a recently abandoned / opened cart
            ?>

				<span style="color:gray;"'>No Products In The Cart</span> <?php 
            av8_tooltip(__('When a customer adds items to a cart, then abandones the cart for a considerable amount of time, the browser often deletes the cart data. The cart still belongs to the customer, but their brower removed the products. :( But hey! This indicates that they came back. And might be ready to purchase.', 'woocommerce_cart_reports'));
            ?>
				<?php 
        }
        ?>
			</tbody>
		</table>
	</div>
	
    <script type="text/javascript">

    </script>
	<?php 
    }
Example #9
0
                    <?php 
    $_count = 0;
    ?>
                    <?php 
    foreach ($deals as $key => $id) {
        $product = new WC_Product($id);
        $time_sale = get_post_meta($product->id, '_sale_price_dates_to', true);
        ?>
                        <div class="item<?php 
        echo $key == 0 ? ' active' : '';
        ?>
">
                            <div class="product-block product">
                                <div class="product-image">
                                    <?php 
        echo $product->get_image('shop_catalog_image_size');
        ?>
                                </div>

                                <div class="product-meta">
                                    <div class="name">
                                        <a href="<?php 
        echo esc_url(get_permalink($product->id));
        ?>
"><?php 
        echo $product->get_title();
        ?>
</a>
                                    </div>
                                    <div class="rating clearfix ">
                                        <?php 
Example #10
0
while ($products->have_posts()) {
    ?>
						<tr>
							<?php 
    $products->the_post();
    ?>
							<?php 
    $p = new WC_Product(get_the_ID());
    ?>
							<td><div>
								<a href="<?php 
    echo $p->add_to_cart_url();
    ?>
">
									<?php 
    echo $p->get_image(array(30, 30)) . ' ';
    the_title();
    ?>
								</a>
							</div></td>
							<td><div><?php 
    echo $p->get_price_html();
    ?>
</div></td>
							<td class="add"><a data-shop="<?php 
    the_ID();
    ?>
" class="button add-to-cart" href="#" title="Add to cart">+</a></td>
						</tr>
					<?php 
}
Example #11
0
/**
 * Build a Google Shopping Content Product from a WC Product
 * @param WC_Product $wc_product
 * @return Google_Service_ShoppingContent_Product
 */
function woogle_build_product($wc_product)
{
    // Create Google Shopping Content Product
    require_once plugin_dir_path(woogle_get_plugin_file()) . 'vendor/google-api-php-client/src/Google/Service/ShoppingContent.php';
    $product = new Google_Service_ShoppingContent_Product();
    // Custom Attributes
    $product_custom_attributes = array();
    // Product identifiers
    $sku = $wc_product->get_sku();
    if (empty($sku)) {
        if ($wc_product->is_type('variation')) {
            $product->setOfferId($wc_product->variation_id);
        } else {
            $product->setOfferId($wc_product->id);
        }
    } else {
        $product->setOfferId($sku);
    }
    if ($wc_product->is_type('variation')) {
        $product->setItemGroupId($wc_product->parent->id);
    }
    $woocommerce_id_attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
    $woocommerce_id_attribute->setName('woocommerce_id');
    $woocommerce_id_attribute->setValue($wc_product->id);
    $woocommerce_id_attribute->setType('int');
    $product_custom_attributes[] = $woocommerce_id_attribute;
    // Title
    $woogle_title = get_post_meta($wc_product->id, '_woogle_title', true);
    if (!empty($woogle_title)) {
        $product->setTitle(html_entity_decode(strip_tags($woogle_title)));
    } else {
        $product->setTitle(html_entity_decode(strip_tags($wc_product->get_title())));
    }
    // Description
    $woogle_description = get_post_meta($wc_product->id, '_woogle_description', true);
    if (!empty($woogle_description)) {
        $product->setDescription(html_entity_decode(strip_tags($woogle_description)));
    } else {
        $product->setDescription(html_entity_decode(strip_tags($wc_product->post->post_content)));
    }
    $product->setLink($wc_product->get_permalink());
    $image = $wc_product->get_image();
    $post_thumbnail_id = get_post_thumbnail_id($wc_product->id);
    if ($post_thumbnail_id) {
        $image_src = wp_get_attachment_image_src($post_thumbnail_id);
        $product->setImageLink(@$image_src[0]);
    }
    $product->setContentLanguage(substr(get_locale(), 0, 2));
    $product->setTargetCountry(WC()->countries->get_base_country());
    $product->setChannel('online');
    $product->setAvailability($wc_product->is_in_stock() ? 'in stock' : 'out of stock');
    // Condition
    $condition = get_post_meta($wc_product->id, '_woogle_condition', true);
    if (!empty($condition)) {
        $product->setCondition($condition);
    } else {
        $product->setcondition('new');
    }
    // Category
    $category = get_post_meta($wc_product->id, '_woogle_category', true);
    if (!empty($category)) {
        $product->setGoogleProductCategory($category);
    }
    // Brand
    $brand = get_post_meta($wc_product->id, '_woogle_brand', true);
    if (!empty($brand)) {
        $product->setBrand($brand);
    }
    // GTIN
    $gtin = get_post_meta($wc_product->id, '_woogle_gtin', true);
    if (!empty($gtin)) {
        $product->setGtin($gtin);
    }
    // MPN
    $mpn = get_post_meta($wc_product->id, '_woogle_mpn', true);
    if (!empty($mpn)) {
        $product->setMpn($mpn);
    }
    if (empty($gtin) && empty($mpn)) {
        $product->setIdentifierExists(false);
    }
    // Price
    $price = new Google_Service_ShoppingContent_Price();
    $price->setValue($wc_product->get_regular_price());
    $price->setCurrency(get_woocommerce_currency());
    $product->setPrice($price);
    // Sale price
    $wc_sale_price = $wc_product->get_sale_price();
    if (!empty($wc_sale_price)) {
        $sale_price = new Google_Service_ShoppingContent_Price();
        $sale_price->setValue($wc_sale_price);
        $sale_price->setCurrency(get_woocommerce_currency());
        $product->setSalePrice($sale_price);
        $post_id = $wc_product->is_type('variation') ? $wc_product->variation_id : $wc_product->id;
        $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
        $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
        if (!empty($sale_price_dates_from) && !empty($sale_price_dates_to)) {
            $effective_date_start = date('c', intval($sale_price_dates_from));
            $effective_date_end = date('c', intval($sale_price_dates_to));
            $product->setSalePriceEffectiveDate("{$effective_date_start}/{$effective_date_end}");
        }
    }
    // Shipping fields
    // Shipping weight
    $wc_product_weight = $wc_product->get_weight();
    if (!empty($wc_product_weight)) {
        $shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
        $shipping_weight->setValue($wc_product_weight);
        $shipping_weight->setUnit(get_option('woocommerce_weight_unit', 'kg'));
        $product->setShippingWeight($shipping_weight);
    }
    // Shipping dimensions
    $wc_dimension_unit = get_option('woocommerce_dimension_unit', 'cm');
    $wc_product_length = $wc_product->get_length();
    if (!empty($wc_product_length)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_length);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingLength($dimension);
    }
    $wc_product_width = $wc_product->get_width();
    if (!empty($wc_product_width)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_width);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingWidth($dimension);
    }
    $wc_product_height = $wc_product->get_height();
    if (!empty($wc_product_height)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_height);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingHeight($dimension);
    }
    // Attributes
    $color = null;
    $material = null;
    $pattern = null;
    $size = null;
    $age_group = null;
    $gender = null;
    $adult = null;
    if ($wc_product->is_type('variation')) {
        // Variable product
        $wc_variation_attributes = $wc_product->get_variation_attributes();
        foreach ($wc_variation_attributes as $name => $value) {
            if (!empty($value)) {
                $attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
                $attribute->setName($name);
                $attribute->setValue($value);
                $attribute->setType('text');
                $product_custom_attributes[] = $attribute;
                // Google attributes
                if (empty($color)) {
                    $color = woogle_maybe_get_attribute('color', $name, $value);
                }
                if (empty($material)) {
                    $material = woogle_maybe_get_attribute('material', $name, $value);
                }
                if (empty($pattern)) {
                    $pattern = woogle_maybe_get_attribute('pattern', $name, $value);
                }
                if (empty($size)) {
                    $size = woogle_maybe_get_attribute('size', $name, $value);
                }
                if (empty($age_group)) {
                    $age_group = woogle_maybe_get_attribute('age-group', $name, $value);
                }
                if (empty($gender)) {
                    $gender = woogle_maybe_get_attribute('gender', $name, $value);
                }
                if (empty($adult)) {
                    $adult = woogle_maybe_get_attribute('adult', $name, $value);
                }
            }
        }
    } else {
        // Simple product
        $wc_attributes = $wc_product->get_attributes();
        foreach ($wc_attributes as $name => $wc_attribute) {
            if ($wc_attribute['is_taxonomy']) {
                $term_values = array();
                $terms = wp_get_post_terms($wc_product->id, $name);
                foreach ($terms as $term) {
                    $term_values[] = $term->slug;
                }
                if (!empty($term_values)) {
                    $value = implode(',', $term_values);
                    $attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
                    $attribute->setName($name);
                    $attribute->setValue($value);
                    $attribute->setType('text');
                    $product_custom_attributes[] = $attribute;
                    // Google attributes
                    if (empty($color)) {
                        $color = woogle_maybe_get_attribute('color', $name, $value);
                    }
                    if (empty($material)) {
                        $material = woogle_maybe_get_attribute('material', $name, $value);
                    }
                    if (empty($pattern)) {
                        $pattern = woogle_maybe_get_attribute('pattern', $name, $value);
                    }
                    if (empty($size)) {
                        $size = woogle_maybe_get_attribute('size', $name, $value);
                    }
                    if (empty($age_group)) {
                        $age_group = woogle_maybe_get_attribute('age-group', $name, $value);
                    }
                    if (empty($gender)) {
                        $gender = woogle_maybe_get_attribute('gender', $name, $value);
                    }
                    if (empty($adult)) {
                        $adult = woogle_maybe_get_attribute('adult', $name, $value);
                    }
                }
            }
        }
    }
    /*
     * Physical properties
     */
    // Color
    if (empty($color)) {
        $color = get_post_meta($wc_product->id, '_woogle_color', true);
    }
    if (!empty($color)) {
        $product->setColor($color);
    }
    // Material
    if (empty($material)) {
        $material = get_post_meta($wc_product->id, '_woogle_material', true);
    }
    if (!empty($material)) {
        $product->setMaterial($material);
    }
    // Pattern
    if (empty($pattern)) {
        $pattern = get_post_meta($wc_product->id, '_woogle_pattern', true);
    }
    if (!empty($pattern)) {
        $product->setPattern($pattern);
    }
    // Size
    if (empty($size)) {
        $size = get_post_meta($wc_product->id, '_woogle_size', true);
    }
    if (!empty($size)) {
        $product->setSizes(explode(', ', $size));
        $product->setSizeSystem(WC()->countries->get_base_country());
    }
    /*
     * Target consumer
     */
    // Age Group
    if (empty($age_group)) {
        $age_group = get_post_meta($wc_product->id, '_woogle_age_group', true);
    }
    if (!empty($age_group)) {
        $product->setAgeGroup($age_group);
    }
    // Gender
    if (empty($gender)) {
        $gender = get_post_meta($wc_product->id, '_woogle_gender', true);
    }
    if (!empty($gender)) {
        $product->setGender($gender);
    }
    // Gender
    if (empty($adult)) {
        $adult = get_post_meta($wc_product->id, '_woogle_adult', true);
    }
    if (!empty($adult) && $adult != 'no') {
        $product->setAdult(true);
    }
    $product->setCustomAttributes($product_custom_attributes);
    return $product;
}