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


PHP WC_Product_Variation::get_sku方法代码示例

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


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

示例1: array

 /**
  * Test variable and variations.
  *
  * @since 2.7.0
  */
 function test_variables_and_variations()
 {
     $product = new WC_Product_Variable();
     $product->set_name('Variable Product');
     $attribute = new WC_Product_Attribute();
     $attribute->set_id(0);
     $attribute->set_name('pa_color');
     $attribute->set_options(explode(WC_DELIMITER, 'green | red'));
     $attribute->set_visible(false);
     $attribute->set_variation(true);
     $product->set_attributes(array($attribute));
     $product->save();
     $this->assertEquals('Variable Product', $product->get_name());
     $variation = new WC_Product_Variation();
     $variation->set_name('Variation #1 of Dummy Variable CRUD Product');
     $variation->set_parent_id($product->get_id());
     $variation->set_regular_price(10);
     $variation->set_sku('CRUD DUMMY SKU VARIABLE GREEN');
     $variation->set_manage_stock('no');
     $variation->set_downloadable('no');
     $variation->set_virtual('no');
     $variation->set_stock_status('instock');
     $variation->set_attributes(array('pa_color' => 'green'));
     $variation->save();
     $this->assertEquals('Variation #1 of Dummy Variable CRUD Product', $variation->get_name());
     $this->assertEquals('CRUD DUMMY SKU VARIABLE GREEN', $variation->get_sku());
     $this->assertEquals(10, $variation->get_price());
     $product = new WC_Product_Variable($product->get_id());
     $children = $product->get_children();
     $this->assertEquals($variation->get_id(), $children[0]);
     $expected_attributes = array('pa_color' => array('green'));
     $this->assertEquals($expected_attributes, $product->get_variation_attributes());
     $variation_2 = new WC_Product_Variation();
     $variation_2->set_name('Variation #2 of Dummy Variable CRUD Product');
     $variation_2->set_parent_id($product->get_id());
     $variation_2->set_regular_price(10);
     $variation_2->set_sku('CRUD DUMMY SKU VARIABLE RED');
     $variation_2->set_manage_stock('no');
     $variation_2->set_downloadable('no');
     $variation_2->set_virtual('no');
     $variation_2->set_stock_status('instock');
     $variation_2->set_attributes(array('pa_color' => 'red'));
     $variation_2->save();
     $this->assertEquals('Variation #2 of Dummy Variable CRUD Product', $variation_2->get_name());
     $this->assertEquals('CRUD DUMMY SKU VARIABLE RED', $variation_2->get_sku());
     $this->assertEquals(10, $variation_2->get_price());
     $product = new WC_Product_Variable($product->get_id());
     $children = $product->get_children();
     $this->assertEquals($variation_2->get_id(), $children[1]);
     $this->assertEquals(2, count($children));
     $expected_attributes = array('pa_color' => array('green', 'red'));
     $this->assertEquals($expected_attributes, $product->get_variation_attributes());
     $variation_2->set_name('UPDATED - Variation #2 of Dummy Variable CRUD Product');
     $variation_2->set_regular_price(15);
     $variation_2->set_sale_price(9.99);
     $variation_2->set_date_on_sale_to('32532537600');
     $variation_2->save();
     $product = new WC_Product_Variable($product->get_id());
     $expected_prices['price'][$children[0]] = 10.0;
     $expected_prices['price'][$children[1]] = 9.99;
     $expected_prices['regular_price'][$children[0]] = 10.0;
     $expected_prices['regular_price'][$children[1]] = 15.0;
     $expected_prices['sale_price'][$children[0]] = 10.0;
     $expected_prices['sale_price'][$children[1]] = 9.99;
     $this->assertEquals($expected_prices, $product->get_variation_prices());
     $this->assertEquals('UPDATED - Variation #2 of Dummy Variable CRUD Product', $variation_2->get_name());
     $product->set_name('Renamed Variable Product');
     $product->save();
     $this->assertEquals('Renamed Variable Product', $product->get_name());
     $product->delete();
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:76,代码来源:data-store.php

示例2: format_wc_variation_for_square_api

 /**
  * Convert a WC Product or Variation into a Square ItemVariation
  * See: https://docs.connect.squareup.com/api/connect/v1/#datatype-itemvariation
  *
  * @param WC_Product|WC_Product_Variation $variation
  * @param bool                            $include_inventory
  * @return array Formatted as a Square ItemVariation
  */
 public static function format_wc_variation_for_square_api($variation, $include_inventory = false)
 {
     $formatted = array('name' => null, 'pricing_type' => null, 'price_money' => null, 'sku' => null, 'track_inventory' => null, 'inventory_alert_type' => null, 'inventory_alert_threshold' => null, 'user_data' => null);
     if ($variation instanceof WC_Product) {
         $formatted['name'] = __('Regular', 'woocommerce-square');
         $formatted['price_money'] = array('currency_code' => apply_filters('woocommerce_square_currency', get_woocommerce_currency()), 'amount' => $variation->get_display_price() * 100);
         $formatted['sku'] = $variation->get_sku();
         if ($include_inventory && $variation->managing_stock()) {
             $formatted['track_inventory'] = true;
         }
     }
     if ($variation instanceof WC_Product_Variation) {
         $formatted['name'] = implode(', ', $variation->get_variation_attributes());
     }
     return array_filter($formatted);
 }
开发者ID:lilweirdward,项目名称:blofishwordpress,代码行数:24,代码来源:class-wc-square-utils.php

示例3: wpp_export

function wpp_export($export)
{
    error_reporting(0);
    ob_clean();
    $export = addslashes(substr(strip_tags($_GET['wpp_export']), 0, 5));
    @set_time_limit(864000);
    if (ini_get('max_execution_time') != 864000) {
        @ini_set('max_execution_time', 864000);
    }
    $post_id = url_to_postid($_SERVER['REQUEST_URI']);
    $post = get_post($post_id);
    if ($post->post_status != 'publish') {
        return false;
    }
    if (post_password_required($post->ID)) {
        return false;
    }
    $product = get_product($post->ID);
    $out = '';
    if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
        $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'shop_single');
        $wpp_featured_image = $thumbnail[0] ? $thumbnail[0] : $thumbnail[0];
    } else {
        $wpp_featured_image = '';
    }
    if ($thumbnail[1]) {
        $wpp_featured_image = '<img width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" src="' . $thumbnail[0] . '"/>';
    }
    $wpp_price_html = strip_tags($product->get_price_html());
    $wpp_title = $post->post_title;
    $wpp_sku = $product->get_sku();
    $wpp_permalink = $product->get_permalink();
    $wpp_stock = $product->get_stock_quantity();
    $wpp_rating = strip_tags($product->get_rating_html());
    $wpp_categories = $product->get_categories(', ');
    $wpp_tags = $product->get_tags(', ');
    $wpp_summary = wpp_text_filter($post->post_excerpt);
    $wpp_description = wpp_text_filter($post->post_content);
    $attribute_html = "\r\n<ul>";
    if ($product->enable_dimensions_display()) {
        $attribute_html .= $product->get_dimensions() ? '<li>' . get_option('wpp_ph_dimensions') . ': ' . $product->get_dimensions() . "\r\n</li>" : '';
    }
    $attribute_html .= $product->get_weight() ? '<li>' . get_option('wpp_ph_weight') . ': ' . $product->get_weight() . ' ' . get_option('woocommerce_weight_unit') . "\r\n</li>" : '';
    if ($product->has_attributes()) {
        $wpp_attributes = $product->get_attributes();
        if (!empty($wpp_attributes)) {
            foreach ($wpp_attributes as $attribute) {
                if (!$attribute['is_visible']) {
                    continue;
                }
                if ($attribute['is_taxonomy']) {
                    $product_terms = wp_get_post_terms($post->ID, $attribute['name']);
                    $p_terms = array();
                    //$attribute_name = ucwords(str_replace('attribute_','',str_replace('pa_','',$attribute['name'])));
                    $attribute_name = wc_attribute_label($attribute['name']);
                    foreach ($product_terms as $p_term) {
                        $p_terms[] = $p_term->name;
                    }
                    $attribute_html .= '<li>' . $attribute_name . ': ' . implode(', ', $p_terms) . "\r\n</li>";
                } else {
                    $attribute_html .= '<li>' . $attribute['name'] . ': ' . $attribute['value'] . "\r\n</li>";
                }
            }
        }
    }
    $attribute_html .= '</ul>';
    $attribute_html = str_replace(array(' |', '|'), ',', $attribute_html);
    $wpp_has_variants = false;
    $wpp_variants = "\r\n<ul>";
    $args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID);
    $variations = get_posts($args);
    if (!empty($variations)) {
        $wpp_has_variants = true;
        foreach ($variations as $variation) {
            $vars = new WC_Product_Variation($variation->ID);
            $wpp_variants .= '<li>' . str_replace($vars->get_sku(), '', html_entity_decode(strip_tags(wpp_text_filter(str_replace('&ndash;', ' - ', $vars->get_formatted_name()))), ENT_QUOTES, "UTF-8")) . "\r\n</li>";
            unset($vars);
        }
        $wpp_variants .= '</ul>';
        $wpp_variants = str_replace(array('<li>  -  ', ',   -  '), array('<li>', '  -  '), $wpp_variants);
    }
    //Post Specific Custom Tabs
    if ($product_meta = get_post_meta($post->ID)) {
        foreach ($product_meta as $meta_key => $meta_value) {
            if (strpos($meta_key, '_wpt_field_') !== FALSE) {
                $custom_tab_slug = str_replace('_wpt_field_', '', $meta_key);
                $custom_tab = get_posts(array('name' => $custom_tab_slug, 'posts_per_page' => 1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish'));
                if (trim($meta_value[0])) {
                    $custom_tab_title_html[] = $custom_tab[0]->post_title;
                    $custom_tab_content_html[] = wpp_text_filter($meta_value[0]);
                }
            }
            continue;
        }
    }
    //General Custom Tabs
    $general_custom_tab = get_posts(array('posts_per_page' => -1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish'));
    foreach ($general_custom_tab as $tab) {
        if (trim($tab->post_content)) {
            $cfkey = '_wpt_field_' . $tab->post_name;
//.........这里部分代码省略.........
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:101,代码来源:functions.php

示例4: explode


//.........这里部分代码省略.........
                 $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 3 || $search_by == 4) {
                 $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1) {
                 $products = array_unique(array_merge(get_posts($products1)));
             } elseif ($search_by == 3) {
                 $products = array_unique(array_merge(get_posts($products2)));
             } else {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2)));
             }
         }
     }
     // JSON encode and echo
     // Initialise suggestions array
     global $post, $woocommerce, $product;
     $suggestions = '';
     foreach ($products as $prod) {
         $hide_product = 'false';
         $post_type = get_post_type($prod);
         $child_args = array('post_parent' => $prod, 'post_type' => 'product_variation');
         $children = get_children($child_args);
         if ('product' == $post_type && empty($children)) {
             $product = wc_get_product($prod);
             $id = $product->id;
             $price_html = $product->get_price_html();
             if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
                 preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
                 $price_html = $matches[1];
             }
             $price_html = strip_tags($price_html);
             $price = $price_html;
             $sku = $product->get_sku();
             $title = get_the_title($product->id);
             $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
             $img = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');
             $img = $img[0];
             if (!empty($img)) {
                 $img = $img;
             } else {
                 $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             }
         } elseif ('product' == $post_type && !empty($children)) {
             $hide_product = 'true';
         } elseif ('product_variation' == $post_type) {
             $product = new WC_Product_Variation($prod);
             $parent = wc_get_product($prod);
             $id = $product->variation_id;
             $price_html = $product->get_price_html();
             if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
                 preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
                 $price_html = $matches[1];
             }
             $price_html = strip_tags($price_html);
             $price = $price_html;
             $sku = $product->get_sku();
             $title = $product->get_title();
             $attributes = $product->get_variation_attributes();
             $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             foreach ($attributes as $name => $value) {
                 $name = str_ireplace("attribute_", "", $name);
                 $terms = get_the_terms($product->id, $name);
                 foreach ($terms as $term) {
                     if (strtolower($term->name) == $value) {
                         $value = $term->name;
开发者ID:hslatman,项目名称:woocommerce-bulk-order-form,代码行数:67,代码来源:standard_template.php


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