本文整理汇总了PHP中WC_Product::is_in_stock方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::is_in_stock方法的具体用法?PHP WC_Product::is_in_stock怎么用?PHP WC_Product::is_in_stock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::is_in_stock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_product_data
/**
* Get standard product data that applies to every product type
*
* @since 2.1
* @param WC_Product $product
* @return array
*/
private function get_product_data($product)
{
return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height(), 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array());
}
示例2: woocs_product
function woocs_product($ID, $attr, $currency = true)
{
if (class_exists('WC_Product')) {
$product = new WC_Product($ID);
if ($attr == 'price_tax_inc') {
$p = round($product->get_price_including_tax(), 2);
} elseif ($attr == 'get_price_excluding_tax') {
$p = round($product->get_price_excluding_tax(), 2);
} elseif ($attr == 'get_price') {
$p = round($product->get_price(), 2);
} elseif ($attr == 'get_sale_price') {
$p = round($product->get_sale_price(), 2);
} elseif ($attr == 'get_regular_price') {
$p = round($product->get_regular_price(), 2);
} elseif ($attr == 'get_price_html') {
$p = strip_tags($product->get_price_html());
} elseif ($attr == 'is_in_stock') {
$p = $product->is_in_stock();
}
}
return $p;
}
示例3: switch
/**
* Bundled product availability that takes quantity into account.
*
* @param WC_Product $product the product
* @param int $quantity the quantity
* @return array availability data
*/
function get_bundled_product_availability($product, $quantity)
{
$availability = $class = '';
if ($product->managing_stock()) {
if ($product->is_in_stock() && $product->get_total_stock() > get_option('woocommerce_notify_no_stock_amount') && $product->get_total_stock() >= $quantity) {
switch (get_option('woocommerce_stock_format')) {
case 'no_amount':
$availability = __('In stock', 'woocommerce');
break;
case 'low_amount':
if ($product->get_total_stock() <= get_option('woocommerce_notify_low_stock_amount')) {
$availability = sprintf(__('Only %s left in stock', 'woocommerce'), $product->get_total_stock());
if ($product->backorders_allowed() && $product->backorders_require_notification()) {
$availability .= ' ' . __('(can be backordered)', 'woocommerce');
}
} else {
$availability = __('In stock', 'woocommerce');
}
break;
default:
$availability = sprintf(__('%s in stock', 'woocommerce'), $product->get_total_stock());
if ($product->backorders_allowed() && $product->backorders_require_notification()) {
$availability .= ' ' . __('(can be backordered)', 'woocommerce');
}
break;
}
$class = 'in-stock';
} elseif ($product->backorders_allowed() && $product->backorders_require_notification()) {
if ($product->get_total_stock() >= $quantity || get_option('woocommerce_stock_format') == 'no_amount') {
$availability = __('Available on backorder', 'woocommerce');
} else {
$availability = __('Available on backorder', 'woocommerce') . ' ' . sprintf(__('(only %s left in stock)', 'woocommerce-product-bundles'), $product->get_total_stock());
}
$class = 'available-on-backorder';
} elseif ($product->backorders_allowed()) {
$availability = __('In stock', 'woocommerce');
$class = 'in-stock';
} else {
if ($product->is_in_stock() && $product->get_total_stock() > get_option('woocommerce_notify_no_stock_amount')) {
if (get_option('woocommerce_stock_format') == 'no_amount') {
$availability = __('Insufficient stock', 'woocommerce-product-bundles');
} else {
$availability = __('Insufficient stock', 'woocommerce-product-bundles') . ' ' . sprintf(__('(only %s left in stock)', 'woocommerce-product-bundles'), $product->get_total_stock());
}
$class = 'out-of-stock';
} else {
$availability = __('Out of stock', 'woocommerce');
$class = 'out-of-stock';
}
}
} elseif (!$product->is_in_stock()) {
$availability = __('Out of stock', 'woocommerce');
$class = 'out-of-stock';
}
_deprecated_function('get_bundled_product_availability', '4.8.8', 'WC_Bundled_Item::get_availability()');
return apply_filters('woocommerce_get_bundled_product_availability', array('availability' => $availability, 'class' => $class), $product);
}
示例4: extract
//.........这里部分代码省略.........
$class_name = 'ts-image-link-grid-frame';
} else {
if ($data_grid_machine == 'freewall') {
wp_enqueue_script('ts-extend-freewall');
$class_name = 'ts-image-freewall-grid-frame';
}
}
if (function_exists('vc_shortcode_custom_css_class')) {
$css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $el_class . ' ' . $class_name . ' ' . vc_shortcode_custom_css_class($css, ' '), 'TS_VCSC_WooCommerce_ImageGrid_Basic', $atts);
} else {
$css_class = $class_name . ' ' . $el_class;
}
$fullwidth_allow = "true";
$postCounter = 0;
$modal_gallery = '';
// Front-Edit Message
if ($frontend_edit == "true") {
$modal_gallery .= $grid_message;
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
$matched_terms = 0;
$post_thumbnail = get_the_post_thumbnail();
if ($matched_terms == 0 && ($post_thumbnail != '' || $data_grid_invalid == "false")) {
$postCounter++;
if ($postCounter < $posts_limit + 1) {
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
if ('' != $post_thumbnail) {
$grid_image = wp_get_attachment_image_src(get_post_thumbnail_id(), $content_images_size);
$modal_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
$grid_image = $grid_image[0];
$modal_image = $modal_image[0];
} else {
$grid_image = TS_VCSC_GetResourceURL('images/defaults/no_featured.png');
$modal_image = TS_VCSC_GetResourceURL('images/defaults/no_featured.png');
}
$categories = array();
if (taxonomy_exists($menu_tax)) {
foreach (get_the_terms($loop->post->ID, $menu_tax) as $term) {
array_push($categories, $term->name);
}
$categories = implode($categories, ',');
}
$valid_images++;
$modal_gallery .= '<a style="' . $image_style . '" href="' . get_permalink() . '" target="_blank" title="' . get_the_title() . '">';
$modal_gallery .= '<img id="ts-image-link-picture-' . $randomizer . '-' . $i . '" class="ts-image-link-picture" src="' . $grid_image . '" rel="link-group-' . $randomizer . '" data-include="true" data-image="' . $modal_image . '" width="100%" height="auto" title="' . get_the_title() . '" data-groups="' . $categories . '" data-target="' . $data_grid_target . '" data-link="' . get_permalink() . '">';
$modal_gallery .= '</a>';
$categories = array();
}
}
}
} else {
echo __("No products could be found.", "ts_visual_composer_extend");
}
wp_reset_postdata();
wp_reset_query();
} else {
if ($loop->have_posts()) {
if ($data_grid_machine == 'freewall') {
示例5: 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);
//.........这里部分代码省略.........
示例6: customize_add_to_cart_text
/**
* Apply the shop loop add to cart button text customization
*
* @since 1.2.0
* @param string $text add to cart text
* @param WC_Product $product product object
* @return string modified add to cart text
*/
public function customize_add_to_cart_text($text, $product)
{
// out of stock add to cart text
if (isset($this->filters['out_of_stock_add_to_cart_text']) && !$product->is_in_stock()) {
return $this->filters['out_of_stock_add_to_cart_text'];
}
if (isset($this->filters['add_to_cart_text']) && $product->is_type('simple')) {
// simple add to cart text
return $this->filters['add_to_cart_text'];
} elseif (isset($this->filters['variable_add_to_cart_text']) && $product->is_type('variable')) {
// variable add to cart text
return $this->filters['variable_add_to_cart_text'];
} elseif (isset($this->filters['grouped_add_to_cart_text']) && $product->is_type('grouped')) {
// grouped add to cart text
return $this->filters['grouped_add_to_cart_text'];
} elseif (isset($this->filters['external_add_to_cart_text']) && $product->is_type('external')) {
// external add to cart text
return $this->filters['external_add_to_cart_text'];
}
return $text;
}
示例7: strtotime
$end_date = null;
if (!empty($ticket->end_date)) {
$end_date = strtotime($ticket->end_date . $gmt_offset);
} else {
$end_date = strtotime(tribe_get_end_date(get_the_ID(), false, 'Y-m-d G:i') . $gmt_offset);
}
$start_date = null;
if (!empty($ticket->start_date)) {
$start_date = strtotime($ticket->start_date . $gmt_offset);
}
if ((empty($start_date) || time() > $start_date) && (empty($end_date) || time() < $end_date)) {
$is_there_any_product = true;
echo sprintf('<input type="hidden" name="product_id[]" value="%d">', $ticket->ID);
echo '<tr>';
echo '<td class="woocommerce">';
if ($product->is_in_stock()) {
// Max quantity will be left open if backorders allowed, restricted to 1 if the product is
// constrained to be sold individually or else set to the available stock quantity
$max_quantity = $product->backorders_allowed() ? '' : $product->get_stock_quantity();
$max_quantity = $product->is_sold_individually() ? 1 : $max_quantity;
woocommerce_quantity_input(array('input_name' => 'quantity_' . $ticket->ID, 'input_value' => 0, 'min_value' => 0, 'max_value' => $max_quantity));
$is_there_any_product_to_sell = true;
} else {
echo '<span class="tickets_nostock">' . esc_html__('Out of stock!', 'tribe-wootickets') . '</span>';
}
echo '</td>';
echo '<td nowrap="nowrap" class="tickets_name">';
echo $ticket->name;
echo '</td>';
echo '<td class="tickets_price">';
echo $this->get_price_html($product);
示例8: array
//.........这里部分代码省略.........
}
}
$front_edit_reverse = array("asc" => __('Bottom to Top', "ts_visual_composer_extend"), "desc" => __('Top to Bottom', "ts_visual_composer_extend"));
foreach ($front_edit_reverse as $key => $value) {
if ($key == $sort_order) {
echo '<div>' . __("Initial Order", "ts_visual_composer_extend") . ': ' . $value . '</div>';
}
}
echo '<div>' . __("Show Filter Button", "ts_visual_composer_extend") . ': ' . $filter_menu . '</div>';
echo '<div>' . __("Show Layout Button", "ts_visual_composer_extend") . ': ' . $layout_menu . '</div>';
echo '<div>' . __("Show Sort Criterion Button", "ts_visual_composer_extend") . ': ' . $sort_menu . '</div>';
echo '<div>' . __("Show Directions Buttons", "ts_visual_composer_extend") . ': ' . $directions_menu . '</div>';
echo '</div>';
} else {
$opening .= '<div id="' . $posts_container_id . '" class="ts-isotope-posts-grid-parent ' . ($layout == 'spineTimeline' ? 'ts-timeline ' : 'ts-postsgrid ') . 'ts-timeline-' . $sort_order . ' ts-posts-timeline ' . $isotope_posts_list_class . ' ' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . ';" data-lazy="' . $posts_lazy . '" data-count="' . $posts_limit . '" data-ajax="' . $posts_ajax . '" data-trigger="' . $posts_trigger . '" data-column="' . $column_width . '" data-layout="' . $layout . '" data-sort="' . $sort_by . '" data-order="' . $sort_order . '" data-break="' . $layout_break . '" data-type="' . $post_type . '">';
// Create Individual Post Output
$postCounter = 0;
$postCategories = array();
$categoriesCount = 0;
if (post_type_exists($post_type) && $loop->have_posts()) {
$products .= '<div class="ts-timeline-content">';
$products .= '<ul id="ts-isotope-posts-grid-' . $postsgrid_random . '" class="ts-isotope-posts-grid ts-timeline-list" data-layout="' . $layout . '" data-key="' . $postsgrid_random . '">';
while ($loop->have_posts()) {
$loop->the_post();
$postCounter++;
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
示例9: array
/**
* Add a product to the cart
*
* @param string $product_id contains the id of the product to add to the cart
* @param string $quantity contains the quantity of the item to add
* @param int $variation_id
* @param array $variation attribute values
* @param array $cart_item_data extra cart item data we want to pass into the item
* @return bool
*/
function add_to_cart($product_id, $quantity = 1, $variation_id = '', $variation = '', $cart_item_data = array())
{
global $woocommerce;
if ($quantity < 1) {
return false;
}
// Load cart item data - may be added by other plugins
$cart_item_data = (array) apply_filters('woocommerce_add_cart_item_data', $cart_item_data, $product_id);
// Generate a ID based on product ID, variation ID, variation data, and other cart item data
$cart_id = $this->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data);
// See if this product and its options is already in the cart
$cart_item_key = $this->find_product_in_cart($cart_id);
if ($variation_id > 0) {
$product_data = new WC_Product_Variation($variation_id);
} else {
$product_data = new WC_Product($product_id);
}
// Force quantity to 1 if sold individually
if ($product_data->is_sold_individually()) {
$quantity = 1;
}
// Type/Exists check
if ($product_data->is_type('external') || !$product_data->exists()) {
$woocommerce->add_error(__('This product cannot be purchased.', 'woocommerce'));
return false;
}
// Price set check
if ($product_data->get_price() === '') {
$woocommerce->add_error(__('This product cannot be purchased - the price is not yet set.', 'woocommerce'));
return false;
}
// Stock check - only check if we're managing stock and backorders are not allowed
if (!$product_data->has_enough_stock($quantity)) {
$woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock. We have %s in stock.', 'woocommerce'), $product_data->get_stock_quantity()));
return false;
} elseif (!$product_data->is_in_stock()) {
$woocommerce->add_error(__('You cannot add that product to the cart since the product is out of stock.', 'woocommerce'));
return false;
}
// Downloadable/virtual qty check
if ($product_data->is_sold_individually()) {
$in_cart_quantity = $cart_item_key ? $this->cart_contents[$cart_item_key]['quantity'] + $quantity : $quantity;
// If its greater than 1, its already in the cart
if ($in_cart_quantity > 1) {
$woocommerce->add_error(sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('You already have this item in your cart.', 'woocommerce')));
return false;
}
}
// Stock check - this time accounting for whats already in-cart
$product_qty_in_cart = $this->get_cart_item_quantities();
if ($product_data->managing_stock()) {
// Variations
if ($variation_id && $product_data->variation_has_stock) {
if (isset($product_qty_in_cart[$variation_id]) && !$product_data->has_enough_stock($product_qty_in_cart[$variation_id] + $quantity)) {
$woocommerce->add_error(sprintf(__('<a href="%s" class="button">%s</a> You cannot add that amount to the cart — we have %s in stock and you already have %s in your cart.', 'woocommerce'), get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), $product_data->get_stock_quantity(), $product_qty_in_cart[$variation_id]));
return false;
}
// Products
} else {
if (isset($product_qty_in_cart[$product_id]) && !$product_data->has_enough_stock($product_qty_in_cart[$product_id] + $quantity)) {
$woocommerce->add_error(sprintf(__('<a href="%s" class="button">%s</a> You cannot add that amount to the cart — we have %s in stock and you already have %s in your cart.', 'woocommerce'), get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), $product_data->get_stock_quantity(), $product_qty_in_cart[$product_id]));
return false;
}
}
}
// If cart_item_key is set, the item is already in the cart
if ($cart_item_key) {
$new_quantity = $quantity + $this->cart_contents[$cart_item_key]['quantity'];
$this->set_quantity($cart_item_key, $new_quantity);
} else {
$cart_item_key = $cart_id;
// Add item after merging with $cart_item_data - hook to allow plugins to modify cart item
$this->cart_contents[$cart_item_key] = apply_filters('woocommerce_add_cart_item', array_merge($cart_item_data, array('product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data)), $cart_item_key);
}
do_action('woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data);
$woocommerce->cart_has_contents_cookie(true);
$this->set_session();
return true;
}
示例10: extract
//.........这里部分代码省略.........
}
$output .= '<div id="' . $woo_slider_id . '-container" class="ts-woocommerce-slider-container">';
// Add Progressbar
if ($auto_play == "true" && $show_bar == "true" && $frontend_edit == "false") {
$output .= '<div id="ts-owlslider-progressbar-' . $woo_random . '" class="ts-owlslider-progressbar-holder" style=""><div class="ts-owlslider-progressbar" style="background: ' . $bar_color . '; height: 100%; width: 0%;"></div></div>';
}
// Add Navigation Controls
if ($frontend_edit == "false") {
$output .= '<div id="ts-owlslider-controls-' . $woo_random . '" class="ts-owlslider-controls" style="' . ($auto_play == "true" || $show_navigation == "true" ? "display: block;" : "display: none;") . '">';
$output .= '<div id="ts-owlslider-controls-next-' . $woo_random . '" style="' . ($show_navigation == "true" ? "display: block;" : "display: none;") . '" class="ts-owlslider-controls-next"><span class="ts-ecommerce-arrowright5"></span></div>';
$output .= '<div id="ts-owlslider-controls-prev-' . $woo_random . '" style="' . ($show_navigation == "true" ? "display: block;" : "display: none;") . '" class="ts-owlslider-controls-prev"><span class="ts-ecommerce-arrowleft5"></span></div>';
if ($auto_play == "true") {
$output .= '<div id="ts-owlslider-controls-play-' . $woo_random . '" class="ts-owlslider-controls-play active"><span class="ts-ecommerce-pause"></span></div>';
}
$output .= '</div>';
}
// Front-Edit Message
if ($frontend_edit == "true") {
$output .= $slider_message;
}
// Add Slider
$output .= '<div id="' . $woo_slider_id . '" class="' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . 'px;" data-id="' . $woo_random . '" data-items="' . $products_slide . '" data-breakpointscustom="' . $breakpoints_custom . '" data-breakpointitems="' . $breakpoints_items . '" data-rtl="' . $page_rtl . '" data-loop="' . $items_loop . '" data-navigation="' . $show_navigation . '" data-dots="' . $show_dots . '" data-mobile="' . $animation_mobile . '" data-animationin="' . $animation_in . '" data-animationout="' . $animation_out . '" data-height="' . $auto_height . '" data-play="' . $auto_play . '" data-bar="' . $show_bar . '" data-color="' . $bar_color . '" data-speed="' . $show_speed . '" data-hover="' . $stop_hover . '">';
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
示例11: get_product_data
/**
* Get standard product data that applies to every product type
*
* @since 2.1
* @param WC_Product $product
* @return WC_Product
*/
private function get_product_data($product, $fields = null)
{
if ($fields) {
$field_list = explode(',', $fields);
}
$product_data = array();
if (!$fields || $fields && in_array('title', $field_list)) {
$product_data['title'] = $product->get_title();
}
if (!$fields || $fields && in_array('id', $field_list)) {
$product_data['id'] = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
}
if (!$fields || $fields && in_array('created_at', $field_list)) {
$product_data['created_at'] = $this->server->format_datetime($product->get_post_data()->post_date_gmt);
}
if (!$fields || $fields && in_array('updated_at', $field_list)) {
$product_data['updated_at'] = $this->server->format_datetime($product->get_post_data()->post_modified_gmt);
}
if (!$fields || $fields && in_array('type', $field_list)) {
$product_data['type'] = $product->product_type;
}
if (!$fields || $fields && in_array('status', $field_list)) {
$product_data['status'] = $product->get_post_data()->post_status;
}
if (!$fields || $fields && in_array('downloadable', $field_list)) {
$product_data['downloadable'] = $product->is_downloadable();
}
if (!$fields || $fields && in_array('virtual', $field_list)) {
$product_data['virtual'] = $product->is_virtual();
}
if (!$fields || $fields && in_array('permalink', $field_list)) {
$product_data['permalink'] = $product->get_permalink();
}
if (!$fields || $fields && in_array('sku', $field_list)) {
$product_data['sku'] = $product->get_sku();
}
if (!$fields || $fields && in_array('price', $field_list)) {
$product_data['price'] = $product->get_price();
}
if (!$fields || $fields && in_array('regular_price', $field_list)) {
$product_data['regular_price'] = $product->get_regular_price();
}
if (!$fields || $fields && in_array('sale_price', $field_list)) {
$product_data['sale_price'] = $product->get_sale_price() ? $product->get_sale_price() : null;
}
if (!$fields || $fields && in_array('price_html', $field_list)) {
$product_data['price_html'] = $product->get_price_html();
}
if (!$fields || $fields && in_array('taxable', $field_list)) {
$product_data['taxable'] = $product->is_taxable();
}
if (!$fields || $fields && in_array('tax_status', $field_list)) {
$product_data['tax_status'] = $product->get_tax_status();
}
if (!$fields || $fields && in_array('tax_class', $field_list)) {
$product_data['tax_class'] = $product->get_tax_class();
}
if (!$fields || $fields && in_array('managing_stock', $field_list)) {
$product_data['managing_stock'] = $product->managing_stock();
}
if (!$fields || $fields && in_array('stock_quantity', $field_list)) {
$product_data['stock_quantity'] = $product->get_stock_quantity();
}
if (!$fields || $fields && in_array('in_stock', $field_list)) {
$product_data['in_stock'] = $product->is_in_stock();
}
if (!$fields || $fields && in_array('backorders_allowed', $field_list)) {
$product_data['backorders_allowed'] = $product->backorders_allowed();
}
if (!$fields || $fields && in_array('backordered', $field_list)) {
$product_data['backordered'] = $product->is_on_backorder();
}
if (!$fields || $fields && in_array('sold_individually', $field_list)) {
$product_data['sold_individually'] = $product->is_sold_individually();
}
if (!$fields || $fields && in_array('purchaseable', $field_list)) {
$product_data['purchaseable'] = $product->is_purchasable();
}
if (!$fields || $fields && in_array('featured', $field_list)) {
$product_data['featured'] = $product->is_featured();
}
if (!$fields || $fields && in_array('visible', $field_list)) {
$product_data['visible'] = $product->is_visible();
}
if (!$fields || $fields && in_array('catalog_visibility', $field_list)) {
$product_data['catalog_visibility'] = $product->visibility;
}
if (!$fields || $fields && in_array('on_sale', $field_list)) {
$product_data['on_sale'] = $product->is_on_sale();
}
if (!$fields || $fields && in_array('product_url', $field_list)) {
$product_data['product_url'] = $product->is_type('external') ? $product->get_product_url() : '';
}
//.........这里部分代码省略.........
示例12: extract
//.........这里部分代码省略.........
data-prev="ts-newsticker-controls-prev-' . $woo_random . '"
data-play="ts-newsticker-controls-play-' . $woo_random . '"
data-stop="ts-newsticker-controls-stop-' . $woo_random . '">';
$output .= '<div class="ts-newsticker-elements-frame ' . $newsticker_elements . ' ' . $ticker_border_radius . '" style="">';
// Add Navigation Controls
$output .= '<div id="ts-newsticker-controls-' . $woo_random . '" class="ts-newsticker-controls" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . ' ' . $newsticker_controls . '">';
$output .= '<div id="ts-newsticker-controls-next-' . $woo_random . '" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . '" class="ts-newsticker-controls-next"><span class="ts-ecommerce-arrowright5"></span></div>';
$output .= '<div id="ts-newsticker-controls-prev-' . $woo_random . '" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . '" class="ts-newsticker-controls-prev"><span class="ts-ecommerce-arrowleft5"></span></div>';
$output .= '<div id="ts-newsticker-controls-stop-' . $woo_random . '" class="ts-newsticker-controls-play" style="' . ($ticker_auto == "true" ? "display: block;" : "display: none;") . '"><span class="ts-ecommerce-pause"></span></div>';
$output .= '<div id="ts-newsticker-controls-play-' . $woo_random . '" class="ts-newsticker-controls-play" style="' . ($ticker_auto == "true" ? "display: none;" : "display: block;") . '"><span class="ts-ecommerce-play"></span></div>';
$output .= '</div>';
if ($ticker_side == "left" && $ticker_title == "true") {
$output .= '<div id="ts-newsticker-header-' . $woo_random . '" class="header ' . $ticker_border_radius . '" style="background: ' . $ticker_background . '; color: ' . $ticker_color . '; left: 0;">';
if ($ticker_icon != '' && $ticker_icon != 'transparent' && $ticker_symbol == "true") {
$output .= '<i class="ts-font-icon ' . $ticker_icon . '" style="color: ' . $ticker_paint . '"></i>';
}
$output .= '<span>' . $ticker_header . '</span>';
$output .= '</div>';
}
$output .= '<ul id="ts-newsticker-ticker-' . $woo_random . '" class="newsticker ' . $ticker_border_radius . '" style="' . $newsticker_header . '">';
while ($loop->have_posts()) {
$loop->the_post();
$postCounter++;
if ($postCounter < $posts_limit + 1) {
$postAttributes = 'data-full="' . get_post_time($date_format) . '" data-time="' . get_post_time($time_format) . '" data-author="' . get_the_author() . '" data-date="' . get_post_time('U') . '" data-modified="' . get_the_modified_time('U') . '" data-title="' . get_the_title() . '" data-comments="' . get_comments_number() . '" data-id="' . get_the_ID() . '"';
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
示例13: is_in_stock
/**
* True if the product is in stock and all bundled items are in stock.
*
* @return bool
*/
public function is_in_stock()
{
$is_in_stock = parent::is_in_stock();
if ($is_in_stock) {
if (is_woocommerce()) {
if (!$this->is_synced()) {
$this->sync_bundle();
}
if (!$this->all_items_in_stock()) {
$is_in_stock = false;
}
}
}
return $is_in_stock;
}
示例14:
function is_in_stock()
{
if (!is_admin()) {
if ($this->availability['class'] == 'out-of-stock') {
return false;
}
}
return parent::is_in_stock();
}
示例15: extract
function TS_VCSC_WooCommerce_Rating_Basic_Function($atts, $content = null)
{
global $VISUAL_COMPOSER_EXTENSIONS;
global $product;
global $woocommerce;
ob_start();
if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndForcable == "false") {
wp_enqueue_style('ts-extend-simptip');
wp_enqueue_style('ts-font-ecommerce');
wp_enqueue_style('ts-visual-composer-extend-front');
wp_enqueue_script('ts-visual-composer-extend-front');
}
extract(shortcode_atts(array('best_rated' => 'false', 'id' => '', 'rating_maximum' => 5, 'rating_size' => 24, 'rating_quarter' => 'true', 'rating_title' => 'true', 'rating_auto' => 'true', 'rating_position' => 'top', 'rating_rtl' => 'false', 'rating_symbol' => 'other', 'rating_icon' => '', 'color_rated' => '#FFD800', 'color_empty' => '#e3e3e3', 'caption_show' => 'true', 'caption_position' => 'left', 'caption_digits' => '.', 'caption_danger' => '#d9534f', 'caption_warning' => '#f0ad4e', 'caption_info' => '#5bc0de', 'caption_primary' => '#428bca', 'caption_success' => '#5cb85c', 'title_size' => 24, 'title_truncate' => 'true', 'use_name' => 'true', 'custom_title' => '', 'show_cart' => 'true', 'cart_color' => '#cccccc', 'show_link' => 'true', 'link_color' => '#cccccc', 'tooltip_css' => 'false', 'tooltip_content' => '', 'tooltip_position' => 'ts-simptip-position-top', 'tooltip_style' => '', 'margin_top' => 20, 'margin_bottom' => 20, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
// Final Query Arguments
add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
$meta_query = WC()->query->get_meta_query();
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'desc', 'paged' => 1, 'meta_query' => $meta_query);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
$best_rating = 0;
while ($loop->have_posts()) {
$loop->the_post();
$product_id = get_the_ID();
$product = new WC_Product($product_id);
if ($product_id == $id) {
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
$link = get_permalink();
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
break;
}
}
}
wp_reset_postdata();
wp_reset_query();
if ($rating_title == "true") {
if ($use_name == "true") {
$rating_title = $product_title;
} else {
$rating_title = $custom_title;
}
} else {
$rating_title = '';
}
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
$rating_class = 'ts-rating-stars-heart1';
} else {
if ($rating_icon == "ts-ecommerce-heart") {
$rating_class = 'ts-rating-stars-heart2';
} else {
if ($rating_icon == "ts-ecommerce-thumbsup") {
$rating_class = 'ts-rating-stars-thumb';
} else {
if ($rating_icon == "ts-ecommerce-ribbon4") {
$rating_class = 'ts-rating-stars-ribbon';
}
}
}
}
}
}
}
}
} else {
//.........这里部分代码省略.........