当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Product::get_image方法代码示例

本文整理汇总了PHP中WC_Product::get_image方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_image方法的具体用法?PHP WC_Product::get_image怎么用?PHP WC_Product::get_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Product的用法示例。


在下文中一共展示了WC_Product::get_image方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sv_wc_pip_document_table_row_cells_product_thumbnail

/**
 * 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);
}
开发者ID:skyverge,项目名称:wc-plugins-snippets,代码行数:17,代码来源:custom-column-product-thumbnail.php

示例2: widget

    /**
     * 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');
    }
开发者ID:hscale,项目名称:webento,代码行数:56,代码来源:widget-recent_reviews.php

示例3: _getProductDetails

 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);
 }
开发者ID:hscale,项目名称:webento,代码行数:8,代码来源:class-shareyourcart-woocommerce.php

示例4: woocommerce_order_items_meta_box


//.........这里部分代码省略.........
            }
            // 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']);
            ?>
" />
开发者ID:hscale,项目名称:webento,代码行数:67,代码来源:writepanel-order_data.php

示例5: woocommerce_custom_product_columns

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') {
//.........这里部分代码省略.........
开发者ID:rosslavery,项目名称:woocommerce,代码行数:101,代码来源:product.php

示例6: update_product

 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;
 }
开发者ID:gmorken,项目名称:viacon,代码行数:37,代码来源:viaconjson.php

示例7: get_product_from_post

 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);
//.........这里部分代码省略.........
开发者ID:booklein,项目名称:wpbookle,代码行数:101,代码来源:wcis_plugin.php

示例8: woocommerce_cart_items_meta_box


//.........这里部分代码省略.........
                ?>
					
					<?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;
开发者ID:Junaid-Farid,项目名称:gocnex,代码行数:67,代码来源:cart_edit_interface.php

示例9: foreach

                    <?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 
开发者ID:shubham79,项目名称:Jhintaak,代码行数:31,代码来源:wpo_product_deals.php

示例10:

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 
}
开发者ID:s7web,项目名称:shopByLook,代码行数:31,代码来源:single.php

示例11: woogle_build_product

/**
 * 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);
//.........这里部分代码省略.........
开发者ID:bear12345678,项目名称:keylessoption,代码行数:101,代码来源:api.php


注:本文中的WC_Product::get_image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。