本文整理汇总了PHP中WC_Product::is_type方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::is_type方法的具体用法?PHP WC_Product::is_type怎么用?PHP WC_Product::is_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::is_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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;
}
示例3: 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) : '';
}
示例4: 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;
}
示例5: 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;
}
}
示例6: 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;
}
示例7: foreach
/**
* Pluggable function to render the frontend product page voucher fields
*
* @since 1.2
* @param WC_Product $product the voucher product
*/
function wc_pdf_product_vouchers_render_product_voucher_fields($product)
{
if ($product->is_type('variable')) {
foreach ($product->get_children() as $variation_product_id) {
$products[] = wc_get_product($variation_product_id);
}
} else {
$products[] = $product;
}
foreach ($products as $product) {
$voucher = WC_PDF_Product_Vouchers_Product::get_voucher($product);
if ($voucher) {
$fields = $voucher->get_user_input_voucher_fields();
$images = $voucher->get_image_urls();
if ($fields || $images) {
// load the template file
wc_get_template('single-product/product-voucher.php', array('product' => $product, 'product_id' => isset($product->variation_id) ? $product->variation_id : $product->id, 'voucher' => $voucher, 'fields' => $fields, 'images' => $images), '', wc_pdf_product_vouchers()->get_plugin_path() . '/templates/');
}
}
}
}
示例8: foreach
//.........这里部分代码省略.........
$allowed_variations = get_post_meta($post->ID, '_allowed_variations', true);
$default_attributes = (array) maybe_unserialize(get_post_meta($post->ID, '_bundle_defaults', true));
foreach ($item_ids as $item_id) {
// remove suffix
$sep = explode('_', $item_id);
$product_id = $sep[0];
$title = get_the_title($product_id) . ($product_id != $item_id ? ' #' . $sep[1] : '');
$sku = get_post_meta($product_id, '_sku', true);
if (isset($sku) && $sku) {
$sku = ' (SKU: ' . $sku . ')';
}
if (!$title) {
continue;
}
?>
<div class="wc-bundled-item">
<div class="item-description">
<?php
echo $title . ' – #' . $product_id;
?>
<br/><?php
echo $sku;
?>
</div>
<div class="item-data">
<?php
if ($this->is_wc_v2()) {
$bundled_product = get_product($product_id);
} else {
$bundled_product = new WC_Product($product_id);
}
if ($bundled_product->is_type('variable')) {
?>
<div class="filtering">
<?php
woocommerce_wp_checkbox(array('id' => 'filter_variations_' . $item_id, 'wrapper_class' => 'filter_variations', 'label' => __('Filter Variations', 'woo-bundles'), 'description' => '<img class="help_tip" data-tip="' . __('Check to enable only a subset of the available variations.', 'woo-bundles') . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />'));
?>
</div>
<div class="bundle_variation_filters indented">
<select multiple="multiple" name="allowed_variations[<?php
echo $item_id;
?>
][]" style="width: 450px; display: none; " data-placeholder="Choose variations…" title="Variations" class="chosen_select" > <?php
$args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $product_id, 'fields' => 'ids');
$variations = get_posts($args);
foreach ($variations as $variation) {
$product_custom_fields = get_post_custom($variation);
ksort($product_custom_fields);
$description = '';
foreach ($product_custom_fields as $name => $value) {
if (!strstr($name, 'attribute_')) {
continue;
}
$attribute_name = substr($name, strlen('attribute_'));
$description_name = ucwords($woocommerce->attribute_label($attribute_name));
if (!$value[0]) {
$description_value = __('Any', 'woocommerce') . ' ' . $description_name;
} else {
示例9: bulk_edit_save
/**
* Bulk edit.
*
* @param integer $post_id
* @param WC_Product $product
*/
public function bulk_edit_save($post_id, $product)
{
$old_regular_price = $product->get_regular_price();
$old_sale_price = $product->get_sale_price();
// Save fields
if (!empty($_REQUEST['change_weight']) && isset($_REQUEST['_weight'])) {
$product->set_weight(wc_clean(stripslashes($_REQUEST['_weight'])));
}
if (!empty($_REQUEST['change_dimensions'])) {
if (isset($_REQUEST['_length'])) {
$product->set_length(wc_clean(stripslashes($_REQUEST['_length'])));
}
if (isset($_REQUEST['_width'])) {
$product->set_width(wc_clean(stripslashes($_REQUEST['_width'])));
}
if (isset($_REQUEST['_height'])) {
$product->set_height(wc_clean(stripslashes($_REQUEST['_height'])));
}
}
if (!empty($_REQUEST['_tax_status'])) {
$product->set_tax_status(wc_clean($_REQUEST['_tax_status']));
}
if (!empty($_REQUEST['_tax_class'])) {
$tax_class = wc_clean($_REQUEST['_tax_class']);
if ('standard' == $tax_class) {
$tax_class = '';
}
$product->set_tax_class($tax_class);
}
if (!empty($_REQUEST['_shipping_class'])) {
$shipping_class = '_no_shipping_class' == $_REQUEST['_shipping_class'] ? '' : wc_clean($_REQUEST['_shipping_class']);
$shipping_class_id = $data_store->get_shipping_class_id_by_slug($shipping_class);
if ($shipping_class_id) {
$product->set_shipping_class_id($shipping_class_id);
}
}
if (!empty($_REQUEST['_visibility'])) {
$product->set_catalog_visibility(wc_clean($_REQUEST['_visibility']));
}
if (!empty($_REQUEST['_featured'])) {
$product->set_featured(stripslashes($_REQUEST['_featured']));
}
// Sold Individually
if (!empty($_REQUEST['_sold_individually'])) {
if ('yes' === $_REQUEST['_sold_individually']) {
$product->set_sold_individually('yes');
} else {
$product->set_sold_individually('');
}
}
// Handle price - remove dates and set to lowest
$change_price_product_types = apply_filters('woocommerce_bulk_edit_save_price_product_types', array('simple', 'external'));
$can_product_type_change_price = false;
foreach ($change_price_product_types as $product_type) {
if ($product->is_type($product_type)) {
$can_product_type_change_price = true;
break;
}
}
if ($can_product_type_change_price) {
$price_changed = false;
if (!empty($_REQUEST['change_regular_price'])) {
$change_regular_price = absint($_REQUEST['change_regular_price']);
$regular_price = esc_attr(stripslashes($_REQUEST['_regular_price']));
switch ($change_regular_price) {
case 1:
$new_price = $regular_price;
break;
case 2:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = $old_regular_price + round($old_regular_price * $percent, wc_get_price_decimals());
} else {
$new_price = $old_regular_price + $regular_price;
}
break;
case 3:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = max(0, $old_regular_price - round($old_regular_price * $percent, wc_get_price_decimals()));
} else {
$new_price = max(0, $old_regular_price - $regular_price);
}
break;
default:
break;
}
if (isset($new_price) && $new_price != $old_regular_price) {
$price_changed = true;
$new_price = round($new_price, wc_get_price_decimals());
$product->set_regular_price($new_price);
}
}
if (!empty($_REQUEST['change_sale_price'])) {
//.........这里部分代码省略.........
示例10: hocwp_wc_is_variable
function hocwp_wc_is_variable(WC_Product $product)
{
return $product->is_type('variable');
}
示例11: get_product_meta
/**
* Gets a product meta field value, regardless of product type
*
* @since 3.5.0
* @param WC_Product $product the product
* @param string $field_name the field name
* @return mixed meta value
*/
public static function get_product_meta($product, $field_name)
{
// use magic __get
$meta = $product->{$field_name};
// WC < 2.2.5 magic __get only returns parent meta for custom fields (core fields will work)
if ($product->is_type('variation')) {
$variation_meta = get_post_meta($product->variation_id, '_' . $field_name, true);
$meta = empty($variation_meta) ? $meta : $variation_meta;
}
return $meta;
}
示例12: get_attributes
/**
* Get the attributes for a product or product variation
*
* @since 2.1
* @param WC_Product|WC_Product_Variation $product
* @return array
*/
private function get_attributes($product)
{
$attributes = array();
if ($product->is_type('variation')) {
// variation attributes
foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
// taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
$attributes[] = array('name' => ucwords(str_replace('attribute_', '', str_replace('pa_', '', $attribute_name))), 'option' => $attribute);
}
} else {
foreach ($product->get_attributes() as $attribute) {
$attributes[] = array('name' => ucwords(str_replace('pa_', '', $attribute['name'])), 'position' => $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
}
}
return $attributes;
}
示例13: bulk_edit_save
/**
* Bulk edit
* @param integer $post_id
* @param WC_Product $product
*/
public function bulk_edit_save($post_id, $product)
{
$old_regular_price = $product->regular_price;
$old_sale_price = $product->sale_price;
// Save fields
if (!empty($_REQUEST['change_weight']) && isset($_REQUEST['_weight'])) {
update_post_meta($post_id, '_weight', wc_clean(stripslashes($_REQUEST['_weight'])));
}
if (!empty($_REQUEST['change_dimensions'])) {
if (isset($_REQUEST['_length'])) {
update_post_meta($post_id, '_length', wc_clean(stripslashes($_REQUEST['_length'])));
}
if (isset($_REQUEST['_width'])) {
update_post_meta($post_id, '_width', wc_clean(stripslashes($_REQUEST['_width'])));
}
if (isset($_REQUEST['_height'])) {
update_post_meta($post_id, '_height', wc_clean(stripslashes($_REQUEST['_height'])));
}
}
if (!empty($_REQUEST['_tax_status'])) {
update_post_meta($post_id, '_tax_status', wc_clean($_REQUEST['_tax_status']));
}
if (!empty($_REQUEST['_tax_class'])) {
$tax_class = wc_clean($_REQUEST['_tax_class']);
if ('standard' == $tax_class) {
$tax_class = '';
}
update_post_meta($post_id, '_tax_class', $tax_class);
}
if (!empty($_REQUEST['_stock_status'])) {
$stock_status = wc_clean($_REQUEST['_stock_status']);
if ($product->is_type('variable')) {
foreach ($product->get_children() as $child_id) {
if ('yes' !== get_post_meta($child_id, '_manage_stock', true)) {
wc_update_product_stock_status($child_id, $stock_status);
}
}
WC_Product_Variable::sync_stock_status($post_id);
} else {
wc_update_product_stock_status($post_id, $stock_status);
}
}
if (!empty($_REQUEST['_shipping_class'])) {
$shipping_class = '_no_shipping_class' == $_REQUEST['_shipping_class'] ? '' : wc_clean($_REQUEST['_shipping_class']);
wp_set_object_terms($post_id, $shipping_class, 'product_shipping_class');
}
if (!empty($_REQUEST['_visibility'])) {
if (update_post_meta($post_id, '_visibility', wc_clean($_REQUEST['_visibility']))) {
do_action('woocommerce_product_set_visibility', $post_id, wc_clean($_REQUEST['_visibility']));
}
}
if (!empty($_REQUEST['_featured'])) {
if (update_post_meta($post_id, '_featured', stripslashes($_REQUEST['_featured']))) {
delete_transient('wc_featured_products');
}
}
// Sold Individually
if (!empty($_REQUEST['_sold_individually'])) {
if ($_REQUEST['_sold_individually'] == 'yes') {
update_post_meta($post_id, '_sold_individually', 'yes');
} else {
update_post_meta($post_id, '_sold_individually', '');
}
}
// Handle price - remove dates and set to lowest
if ($product->is_type('simple') || $product->is_type('external')) {
$price_changed = false;
if (!empty($_REQUEST['change_regular_price'])) {
$change_regular_price = absint($_REQUEST['change_regular_price']);
$regular_price = esc_attr(stripslashes($_REQUEST['_regular_price']));
switch ($change_regular_price) {
case 1:
$new_price = $regular_price;
break;
case 2:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = $old_regular_price + round($old_regular_price * $percent, wc_get_price_decimals());
} else {
$new_price = $old_regular_price + $regular_price;
}
break;
case 3:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = max(0, $old_regular_price - round($old_regular_price * $percent, wc_get_price_decimals()));
} else {
$new_price = max(0, $old_regular_price - $regular_price);
}
break;
default:
break;
}
if (isset($new_price) && $new_price != $old_regular_price) {
$price_changed = true;
//.........这里部分代码省略.........
示例14: on_price_html
/**
* Adjust discounted product price HTML
*
* @since 1.3.0
* @param string $html
* @param WC_Product $product
* @return float|string
*/
public function on_price_html($html, $product)
{
/**
* Controls whether or not member prices should use discount format when displayed
*
* @since 1.3.0
* @param bool $use_discount_format Defaults to true
*/
if (!apply_filters('wc_memberships_member_prices_use_discount_format', true)) {
return $html;
}
$tax_display_mode = get_option('woocommerce_tax_display_shop');
$this->disable_price_adjustments();
$base_price = 'incl' == $tax_display_mode ? $product->get_price_including_tax() : $product->get_price_excluding_tax();
$product_id = $product->is_type('variation') ? $product->variation_id : $product->id;
$this->enable_price_adjustments();
if (!$this->has_discounted_price($base_price, $product_id)) {
return $html;
}
/**
* Controls whether or not member prices should display sale prices as well
*
* @since 1.3.0
* @param bool $display_sale_price Defaults to false
*/
$display_sale_price = apply_filters('wc_memberships_member_prices_display_sale_price', false);
add_filter('woocommerce_get_variation_prices_hash', array($this, 'nonmember_variation_prices_hash'), 10, 3);
if (!$display_sale_price) {
add_filter('woocommerce_product_is_on_sale', array($this, 'disable_sale_price'));
}
$this->disable_price_adjustments();
$this->disable_price_html_adjustments();
$_html = $product->get_price_html();
$this->enable_price_adjustments();
$this->enable_price_html_adjustments();
remove_filter('woocommerce_get_variation_prices_hash', array($this, 'nonmember_variation_prices_hash'));
if (!$display_sale_price) {
remove_filter('woocommerce_product_is_on_sale', array($this, 'disable_sale_price'));
}
if ($html != $_html) {
$html = '<del>' . $_html . '</del> <ins> ' . $html . '</ins>';
}
return $html;
}
开发者ID:eugene-gromky-co,项目名称:mindfulnesssummit,代码行数:52,代码来源:class-wc-memberships-member-discounts.php
示例15: 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
*/
function add_to_cart($product_id, $quantity = 1, $variation_id = '', $variation = '')
{
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', array(), $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);
}
// 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;
}
if ($cart_item_key) {
$quantity = $quantity + $this->cart_contents[$cart_item_key]['quantity'];
// Stock check - this time accounting for whats already in-cart
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 and you already have %s in your cart.', 'woocommerce'), $product_data->get_stock_quantity(), $this->cart_contents[$cart_item_key]['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;
}
$this->set_quantity($cart_item_key, $quantity);
} else {
// Add item after merging with $cart_item_data - hook to allow plugins to modify cart item
$this->cart_contents[$cart_id] = 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)));
}
$this->set_session();
return true;
}