• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WC_Product类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: is_bulk_variation_form

 public function is_bulk_variation_form()
 {
     global $post;
     if (!$post) {
         return false;
     }
     /** Remove validation (_bv_type) -- 03/02/2016 **/
     if (!is_product()) {
         return false;
     }
     /****/
     /** Validate if exits role -- 03/02/2016 **/
     if ($this->role_exists('wholesale_customer')) {
         if (!current_user_can('wholesale_customer')) {
             return false;
         }
     }
     // 2.0 Compat
     if (function_exists('get_product')) {
         $product = get_product($post->ID);
     } else {
         $product = new WC_Product($post->ID);
     }
     if ($product && !$product->has_child() && !$product->is_type('variable')) {
         return false;
     }
     return apply_filters('woocommerce_bv_render_form', true);
 }
开发者ID:jmagallanes,项目名称:cultura-woo-bulk-variations,代码行数:28,代码来源:cultura-woo-bulk-variations.php


示例2: test_product_getters_and_setters

 /**
  * Test product setters and getters
  * @since 2.7.0
  */
 public function test_product_getters_and_setters()
 {
     global $wpdb;
     $attributes = array();
     $attribute = new WC_Product_Attribute();
     $attribute->set_id(0);
     $attribute->set_name('Test Attribute');
     $attribute->set_options(array('Fish', 'Fingers'));
     $attribute->set_position(0);
     $attribute->set_visible(true);
     $attribute->set_variation(false);
     $attributes['test-attribute'] = $attribute;
     $getters_and_setters = array('name' => 'Test', 'slug' => 'test', 'status' => 'publish', 'catalog_visibility' => 'search', 'featured' => false, 'description' => 'Hello world', 'short_description' => 'hello', 'sku' => 'TEST SKU', 'regular_price' => 15.0, 'sale_price' => 10.0, 'date_on_sale_from' => '1475798400', 'date_on_sale_to' => '1477267200', 'total_sales' => 20, 'tax_status' => 'none', 'tax_class' => '', 'manage_stock' => true, 'stock_quantity' => 10, 'stock_status' => 'instock', 'backorders' => 'notify', 'sold_individually' => false, 'weight' => 100, 'length' => 10, 'width' => 10, 'height' => 10, 'upsell_ids' => array(2, 3), 'cross_sell_ids' => array(4, 5), 'parent_id' => 0, 'reviews_allowed' => true, 'default_attributes' => array(), 'purchase_note' => 'A note', 'menu_order' => 2, 'gallery_image_ids' => array(), 'download_expiry' => -1, 'download_limit' => 5, 'attributes' => $attributes);
     $product = new WC_Product();
     foreach ($getters_and_setters as $function => $value) {
         $product->{"set_{$function}"}($value);
     }
     $product->save();
     $product = new WC_Product_Simple($product->get_id());
     foreach ($getters_and_setters as $function => $value) {
         $this->assertEquals($value, $product->{"get_{$function}"}(), $function);
     }
     $image_url = media_sideload_image("https://cldup.com/Dr1Bczxq4q.png", $product->get_id(), '', 'src');
     $image_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $image_url));
     $product->set_image_id($image_id[0]);
     $product->save();
     $this->assertEquals($image_id[0], $product->get_image_id());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:32,代码来源:data.php


示例3: get_product_display_price

 /**
  * Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
  * Should be safe to remove when we drop WC 2.2 compatibility
  *
  * @param  WC_Product $product the product object
  * @param  string     $price   to calculate, left blank to just use get_price()
  * @param  integer    $qty     passed on to get_price_including_tax() or get_price_excluding_tax()
  * @return string
  */
 public static function get_product_display_price($product, $price = '', $qty = 1)
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         return $product->get_display_price($price, $qty);
     } else {
         if ($price === '') {
             $price = $product->get_price();
         }
         $tax_display_mode = get_option('woocommerce_tax_display_shop');
         $display_price = $tax_display_mode == 'incl' ? $product->get_price_including_tax($qty, $price) : $product->get_price_excluding_tax($qty, $price);
         return $display_price;
     }
 }
开发者ID:baden03,项目名称:access48,代码行数:22,代码来源:class-wc-price-calculator-compatibility.php


示例4: sv_wc_csv_export_order_line_item_sku

/**
 * Replaces variation SKUs with the parent SKU
 *
 * @param array $line_item the line item's data in the export
 * @param array $item the order item being exported
 * @param \WC_Product $product the product associated with the item
 * @return array - updated line item
 */
function sv_wc_csv_export_order_line_item_sku($line_item, $item, $product)
{
    if ($product->is_type('variation')) {
        $line_item['sku'] = $product->parent->get_sku();
    }
    return $line_item;
}
开发者ID:skyverge,项目名称:wc-plugins-snippets,代码行数:15,代码来源:modify-line-item-data.php


示例5: 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


示例6: woocommerce_redirects

/**
 * Handle redirects before content is output - hooked into template_redirect so is_page works
 **/
function woocommerce_redirects()
{
    global $woocommerce, $wp_query;
    // When default permalinks are enabled, redirect shop page to post type archive url
    if (isset($_GET['page_id']) && $_GET['page_id'] > 0 && get_option('permalink_structure') == "" && $_GET['page_id'] == woocommerce_get_page_id('shop')) {
        wp_safe_redirect(get_post_type_archive_link('product'));
        exit;
    }
    // When on the checkout with an empty cart, redirect to cart page
    if (is_page(woocommerce_get_page_id('checkout')) && sizeof($woocommerce->cart->get_cart()) == 0) {
        wp_redirect(get_permalink(woocommerce_get_page_id('cart')));
        exit;
    }
    // When on pay page with no query string, redirect to checkout
    if (is_page(woocommerce_get_page_id('pay')) && !isset($_GET['order'])) {
        wp_redirect(get_permalink(woocommerce_get_page_id('checkout')));
        exit;
    }
    // My account page redirects (logged out)
    if (!is_user_logged_in() && (is_page(woocommerce_get_page_id('edit_address')) || is_page(woocommerce_get_page_id('view_order')) || is_page(woocommerce_get_page_id('change_password')))) {
        wp_redirect(get_permalink(woocommerce_get_page_id('myaccount')));
        exit;
    }
    // Redirect to the product page if we have a single product
    if (is_search() && is_post_type_archive('product') && get_option('woocommerce_redirect_on_single_search_result') == 'yes') {
        if ($wp_query->post_count == 1) {
            $product = new WC_Product($wp_query->post->ID);
            if ($product->is_visible()) {
                wp_safe_redirect(get_permalink($product->id), 302);
            }
            exit;
        }
    }
}
开发者ID:eddiewilson,项目名称:new-ke,代码行数:37,代码来源:woocommerce-functions.php


示例7: ss_upsells_display

function ss_upsells_display( $product ){
 $settings = get_option ( 'shopstyler' );
 $product = new WC_Product( get_the_ID() );	
 $upsells = $product->get_upsells();
 if (!$upsells)
        return;

	$meta_query = WC()->query->get_meta_query();

    $args = array(
        'post_type' => 'product',
        'ignore_sticky_posts' => 1,
        'no_found_rows' => $settings['woo_upsell_limit'],
        'posts_per_page' => $posts_per_page,
        'orderby' => $orderby,
        'post__in' => $upsells,
        'post__not_in' => array($product->id),
        'meta_query' => $meta_query
    );

    $wp_query = new WP_Query($args);
	if ( $wp_query->have_posts() ){
		ss_render_query ( $wp_query , $settings['woo_upsell_label'] );
	}
}
开发者ID:swina,项目名称:ShopStyler-2,代码行数:25,代码来源:ss-single-functions.php


示例8: validate_checkout_listener

 /**
  * Validate Klarna order
  * Checks order items' stock status.
  *
  * @since 1.0.0
  */
 public static function validate_checkout_listener()
 {
     // Read the post body
     $post_body = file_get_contents('php://input');
     // Convert post body into native object
     $data = json_decode($post_body, true);
     $all_in_stock = true;
     if (get_option('woocommerce_manage_stock') == 'yes') {
         $cart_items = $data['cart']['items'];
         foreach ($cart_items as $cart_item) {
             if ('physical' == $cart_item['type']) {
                 $cart_item_product = new WC_Product($cart_item['reference']);
                 if (!$cart_item_product->has_enough_stock($cart_item['quantity'])) {
                     $all_in_stock = false;
                 }
             }
         }
     }
     if ($all_in_stock) {
         header('HTTP/1.0 200 OK');
     } else {
         header('HTTP/1.0 303 See Other');
         header('Location: ' . WC()->cart->get_cart_url());
     }
 }
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:31,代码来源:class-klarna-validate.php


示例9: product_get_id

 /**
  * Backports WC_Product::get_id() method to 2.4.x
  *
  * @link https://github.com/woothemes/woocommerce/pull/9765
  *
  * @since 4.2.0
  * @param \WC_Product $product product object
  * @return string|int product ID
  */
 public static function product_get_id(WC_Product $product)
 {
     if (self::is_wc_version_gte_2_5()) {
         return $product->get_id();
     } else {
         return $product->is_type('variation') ? $product->variation_id : $product->id;
     }
 }
开发者ID:DustinHartzler,项目名称:TheCLEFT,代码行数:17,代码来源:class-sv-wc-plugin-compatibility.php


示例10: is_subscription

 /**
  * Checks a given product to determine if it is a subscription.
  * 
  * Can be passed either a product object or product ID.
  *
  * @since 1.0
  */
 public static function is_subscription($product)
 {
     if (!is_object($product)) {
         $product = new WC_Product($product);
     }
     // Shouldn't matter if product is variation as all we need is the product_type
     return $product->is_type(WC_Subscriptions::$name) ? true : false;
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:15,代码来源:class-wc-subscriptions-product.php


示例11: get_name

 protected function get_name(WC_Product $product)
 {
     if ($product->get_sku()) {
         $identifier = $product->get_sku();
     } else {
         $identifier = '#' . (isset($product->variation_id) ? $product->variation_id : $product->id);
     }
     return sprintf('%s - %s', $identifier, $product->get_title());
 }
开发者ID:Automattic,项目名称:woocommerce-connect-client,代码行数:9,代码来源:class-wc-connect-shipping-label.php


示例12: ajax_get_products_per_period

 public function ajax_get_products_per_period()
 {
     $product_num = isset($_POST['product_num']) ? $_POST['product_num'] : 10;
     $start_date = isset($_POST['start_date']) ? $_POST['start_date'] : null;
     $end_date = isset($_POST['end_date']) ? $_POST['end_date'] : null;
     $results = [];
     $stats = $this->get_products_per_period(100, $start_date, $end_date);
     //wcds_var_dump($stats);
     /*Format:
     		array(4) {
     		  [0]=>
     		  array(4) {
     			["total_earning"]=>
     			string(1) "4"
     			["total_purchases"]=>
     			string(1) "4"
     			["prod_id"]=>
     			string(2) "12"
     			["prod_variation_id"]=>
     			string(1) "0"
     		  }
     		  */
     $counter = 0;
     $wpml_helper = new WCDS_Wpml();
     foreach ($stats as $prod_id => $product) {
         //WPML: Merge product stats by id
         $stats[$prod_id]['total_earning'] = round($product['total_earning'], 2);
         $stats[$prod_id]['permalink'] = get_permalink($prod_id);
         if ($wpml_helper->wpml_is_active()) {
             $original_id = $wpml_helper->get_original_id($prod_id);
             $product_temp = new WC_Product($original_id);
             $stats[$prod_id]['prod_title'] = $product_temp->get_title();
             $stats[$prod_id]['permalink'] = get_permalink($original_id);
             //wcds_var_dump($prod_id." -> ".$original_id);
             if (!isset($results[$original_id])) {
                 //wcds_var_dump("new");
                 $results[$original_id] = $stats[$prod_id];
             } else {
                 //wcds_var_dump("update");
                 $results[$original_id]["total_earning"] += $product["total_purchases"];
                 $results[$original_id]["total_earning"] += $product["total_earning"];
                 $results[$original_id]["total_earning"] = round($results[$original_id]['total_earning'], 2);
             }
         } else {
             $results[$prod_id] = $stats[$prod_id];
         }
         if (++$counter == $product_num) {
             break;
         }
     }
     usort($results, function ($a, $b) {
         return $b['total_earning'] - $a['total_earning'];
     });
     echo json_encode($results);
     wp_die();
 }
开发者ID:bear12345678,项目名称:keylessoption,代码行数:56,代码来源:WCDS_Product.php


示例13: 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


示例14: build_line_items

/**
 * Build the line items hash
 * @param array $items
 */
function build_line_items($items)
{
    $line_items = array();
    foreach ($items as $item) {
        $productmeta = new WC_Product($item['product_id']);
        $sku = $productmeta->get_sku();
        $line_items = array_merge($line_items, array(array('name' => $item['name'], 'unit_price' => floatval($item['line_total']) * 100, 'description' => $item['name'], 'quantity' => $item['qty'], 'sku' => $sku, 'type' => $item['type'])));
    }
    return $line_items;
}
开发者ID:pcuervo,项目名称:wp-yolcan,代码行数:14,代码来源:conekta_gateway_helper.php


示例15: test_product_update

 /**
  * Test updating a product.
  *
  * @since 2.7.0
  */
 function test_product_update()
 {
     $product = WC_Helper_Product::create_simple_product();
     $this->assertEquals('10', $product->get_regular_price());
     $product->set_regular_price(15);
     $product->save();
     // Reread from database
     $product = new WC_Product($product->get_id());
     $this->assertEquals('15', $product->get_regular_price());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:15,代码来源:data-store.php


示例16: sv_wc_csv_export_order_line_item_price

/**
 * Add the product price 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 updated line item data
 */
function sv_wc_csv_export_order_line_item_price($line_item, $item, $product)
{
    $new_line_item = array();
    foreach ($line_item as $key => $data) {
        $new_line_item[$key] = $data;
        // add this in the JSON / pipe-format after the SKU
        if ('sku' === $key) {
            $new_line_item['price'] = wc_format_decimal($product->get_price(), 2);
        }
    }
    return $new_line_item;
}
开发者ID:skyverge,项目名称:wc-plugins-snippets,代码行数:20,代码来源:add-item-price-to-order-export.php


示例17: woocommerce_gravityforms_get_updated_price

function woocommerce_gravityforms_get_updated_price()
{
    global $woocommerce;
    header('Cache-Control: no-cache, must-revalidate');
    header('Content-type: application/json');
    $variation_id = isset($_POST['variation_id']) ? $_POST['variation_id'] : '';
    $product_id = isset($_POST['product_id']) ? $_POST['product_id'] : 0;
    $gform_total = isset($_POST['gform_total']) ? $_POST['gform_total'] : 0;
    $product_data = null;
    if (function_exists('get_product')) {
        $product_data = get_product($variation_id > 0 ? $variation_id : $product_id);
    } else {
        if ($variation_id > 0) {
            $product_data = new WC_Product_Variation($variation_id);
        } else {
            $product_data = new WC_Product($product_id);
        }
    }
    $discount_price = false;
    $gforms_discount_price = false;
    $base_price = $product_data->get_price();
    if (class_exists('WC_Dynamic_Pricing')) {
        $working_price = $base_price;
        $dynamic_pricing = WC_Dynamic_Pricing::instance();
        foreach ($dynamic_pricing->modules as $module) {
            if ($module->module_type == 'simple') {
                //Make sure we are using the price that was just discounted.
                $working_price = $discount_price ? $discount_price : $base_price;
                $working_price = $module->get_product_working_price($working_price, $product_data);
                if (floatval($working_price)) {
                    $discount_price = $module->get_discounted_price_for_shop($product_data, $working_price);
                }
            }
        }
        $gforms_base_price = $base_price + $gform_total;
        $gforms_working_price = $base_price + $gform_total;
        foreach ($dynamic_pricing->modules as $module) {
            if ($module->module_type == 'simple') {
                //Make sure we are using the price that was just discounted.
                $gforms_working_price = $gforms_discount_price ? $gforms_discount_price : $gforms_base_price;
                $gforms_working_price = $module->get_product_working_price($gforms_working_price, $product_data);
                if (floatval($gforms_working_price)) {
                    $gforms_discount_price = $module->get_discounted_price_for_shop($product_data, $gforms_working_price);
                }
            }
        }
    }
    $price = $discount_price ? $discount_price : $base_price;
    $gform_final_total = $gforms_discount_price ? $gforms_discount_price : $price + $gform_total;
    $result = array('formattedBasePrice' => apply_filters('woocommerce_gform_base_price', woocommerce_price($price), $product_data), 'formattedTotalPrice' => apply_filters('woocommerce_gform_total_price', woocommerce_price($gform_final_total), $product_data), 'formattedVariationTotal' => apply_filters('woocommerce_gform_variation_total_price', woocommerce_price($gform_total), $product_data));
    echo json_encode($result);
    die;
}
开发者ID:avijitdeb,项目名称:flatterbox.com,代码行数:53,代码来源:gravityforms-product-addons-ajax.php


示例18: get_base_product_price

 public function get_base_product_price($id, $price)
 {
     if (!defined('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING')) {
         define('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING', true);
     }
     $product = new WC_Product($id);
     if ($price == 'product_regular_price') {
         return $product->get_regular_price();
     }
     if ($price == 'product_selling_price') {
         return $product->get_sale_price();
     }
 }
开发者ID:7GRAFIX,项目名称:WooCommerce-Role-Based-Price,代码行数:13,代码来源:class-product-functions.php


示例19: sync_price

 /**
  * Sync grouped product prices with children.
  *
  * @since 2.7.0
  * @param WC_Product|int $product
  */
 public function sync_price(&$product)
 {
     global $wpdb;
     $children_ids = get_posts(array('post_parent' => $product->get_id(), 'post_type' => 'product', 'fields' => 'ids'));
     $prices = $children_ids ? array_unique($wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_price' AND post_id IN ( " . implode(',', array_map('absint', $children_ids)) . " )")) : array();
     delete_post_meta($product->get_id(), '_price');
     delete_transient('wc_var_prices_' . $product->get_id());
     if ($prices) {
         sort($prices);
         // To allow sorting and filtering by multiple values, we have no choice but to store child prices in this manner.
         foreach ($prices as $price) {
             add_post_meta($product->get_id(), '_price', $price, false);
         }
     }
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:21,代码来源:class-wc-product-grouped-data-store-cpt.php


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WC_Product_Variable类代码示例发布时间:2022-05-23
下一篇:
PHP WC_Payment_Gateways类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap