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


PHP WC_Product::get_variation_id方法代码示例

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


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

示例1: vc_gitem_template_attribute_woocommerce_product

/**
 * Gte woocommerce data for product
 *
 * @param $value
 * @param $data
 *
 * @return string
 */
function vc_gitem_template_attribute_woocommerce_product($value, $data)
{
    $label = '';
    /**
     * @var null|Wp_Post $post ;
     * @var string $data ;
     */
    extract(array_merge(array('post' => null, 'data' => ''), $data));
    require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-product.php';
    $product = new WC_Product($post);
    if (preg_match('/_labeled$/', $data)) {
        $data = preg_replace('/_labeled$/', '', $data);
        $label = apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_label', Vc_Vendor_Woocommerce::getProductFieldLabel($data) . ': ');
    }
    $price_format = get_woocommerce_price_format();
    switch ($data) {
        case 'id':
            $value = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
            break;
        case 'sku':
            $value = $product->get_sku();
            break;
        case 'price':
            $value = sprintf($price_format, wc_format_decimal($product->get_price(), 2), get_woocommerce_currency());
            break;
        case 'regular_price':
            $value = sprintf($price_format, wc_format_decimal($product->get_regular_price(), 2), get_woocommerce_currency());
            break;
        case 'sale_price':
            $value = sprintf(get_woocommerce_price_format(), $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : '', get_woocommerce_currency());
            break;
        case 'price_html':
            $value = $product->get_price_html();
            break;
        case 'reviews_count':
            $value = count(get_comments(array('post_id' => $post->ID, 'approve' => 'approve')));
            break;
        case 'short_description':
            $value = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt);
            break;
        case 'dimensions':
            $units = get_option('woocommerce_dimension_unit');
            $value = $product->length . $units . 'x' . $product->width . $units . 'x' . $product->height . $units;
            break;
        case 'raiting_count':
            $value = $product->get_rating_count();
            break;
        case 'weight':
            $value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : '';
            break;
        case 'on_sale':
            $value = $product->is_on_sale() ? 'yes' : 'no';
            // @todo change
            break;
        default:
            $value = $product->{$data};
    }
    return strlen($value) > 0 ? $label . apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_value', $value) : '';
}
开发者ID:chicosilva,项目名称:olharambiental,代码行数:67,代码来源:grid-item-attributes.php

示例2: sv_wc_csv_export_order_line_item_id

/**
 * Add the product id & variation ID to the individual line item entry
 *
 * @param array $line_item the original line item data
 * @param array $item WC order item data
 * @param WC_Product $product the product
 * @return array $line_item	the updated line item data
 */
function sv_wc_csv_export_order_line_item_id($line_item, $item, $product)
{
    $line_item['item_id'] = $product->id;
    $line_item['variation_id'] = '';
    // set the variation id for variable products
    if ($product->is_type('variation')) {
        $line_item['variation_id'] = $product->get_variation_id();
    }
    return $line_item;
}
开发者ID:skyverge,项目名称:wc-plugins-snippets,代码行数:18,代码来源:add-product-ids-to-order-export.php

示例3: get_images

 /**
  * Get the images for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_images($product)
 {
     $images = $attachment_ids = array();
     if ($product->is_type('variation')) {
         if (has_post_thumbnail($product->get_variation_id())) {
             // Add variation image if set
             $attachment_ids[] = get_post_thumbnail_id($product->get_variation_id());
         } elseif (has_post_thumbnail($product->id)) {
             // Otherwise use the parent product featured image if set
             $attachment_ids[] = get_post_thumbnail_id($product->id);
         }
     } else {
         // Add featured image
         if (has_post_thumbnail($product->id)) {
             $attachment_ids[] = get_post_thumbnail_id($product->id);
         }
         // Add gallery images
         $attachment_ids = array_merge($attachment_ids, $product->get_gallery_attachment_ids());
     }
     // Build image data
     foreach ($attachment_ids as $position => $attachment_id) {
         $attachment_post = get_post($attachment_id);
         if (is_null($attachment_post)) {
             continue;
         }
         $attachment = wp_get_attachment_image_src($attachment_id, 'full');
         if (!is_array($attachment)) {
             continue;
         }
         $images[] = array('id' => (int) $attachment_id, 'created_at' => $this->server->format_datetime($attachment_post->post_date_gmt), 'updated_at' => $this->server->format_datetime($attachment_post->post_modified_gmt), 'src' => current($attachment), 'title' => get_the_title($attachment_id), 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), 'position' => (int) $position);
     }
     // Set a placeholder image if the product has no images set
     if (empty($images)) {
         $images[] = array('id' => 0, 'created_at' => $this->server->format_datetime(time()), 'updated_at' => $this->server->format_datetime(time()), 'src' => wc_placeholder_img_src(), 'title' => __('Placeholder', 'woocommerce'), 'alt' => __('Placeholder', 'woocommerce'), 'position' => 0);
     }
     return $images;
 }
开发者ID:haltaction,项目名称:woocommerce,代码行数:44,代码来源:class-wc-api-products.php

示例4: get_product_data

 /**
  * Get product data.
  *
  * @param WC_Product $product
  * @return array
  */
 protected function get_product_data($product)
 {
     $data = array('id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'name' => $product->get_title(), 'slug' => $product->get_post_data()->post_name, 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_post_data()->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'featured' => $product->is_featured(), 'catalog_visibility' => $product->visibility, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), '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->sale_price_dates_from ? date('Y-m-d', $product->sale_price_dates_from) : '', 'date_on_sale_to' => $product->sale_price_dates_to ? date('Y-m-d', $product->sale_price_dates_to) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => (int) get_post_meta($product->id, 'total_sales', true), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => '' !== $product->download_limit ? (int) $product->download_limit : -1, 'download_expiry' => '' !== $product->download_expiry ? (int) $product->download_expiry : -1, 'download_type' => $product->download_type ? $product->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->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' => (int) $product->get_shipping_class_id(), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->is_type('variation') ? $product->parent->id : $product->get_post_data()->post_parent, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->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' => $this->get_product_menu_order($product));
     return $data;
 }
开发者ID:pelmered,项目名称:woocommerce,代码行数:11,代码来源:class-wc-rest-products-controller.php


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