本文整理汇总了PHP中WC_Product::is_featured方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::is_featured方法的具体用法?PHP WC_Product::is_featured怎么用?PHP WC_Product::is_featured使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::is_featured方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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)
{
return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : 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->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->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' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array());
}
示例3: woocommerce_feature_product
/**
* Feature a product from admin
*/
function woocommerce_feature_product()
{
if (!is_admin()) {
die;
}
if (!current_user_can('edit_posts')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'woocommerce'));
}
if (!check_admin_referer('woocommerce-feature-product')) {
wp_die(__('You have taken too long. Please go back and retry.', 'woocommerce'));
}
$post_id = isset($_GET['product_id']) && (int) $_GET['product_id'] ? (int) $_GET['product_id'] : '';
if (!$post_id) {
die;
}
$post = get_post($post_id);
if (!$post) {
die;
}
if ($post->post_type !== 'product') {
die;
}
$product = new WC_Product($post->ID);
if ($product->is_featured()) {
update_post_meta($post->ID, '_featured', 'no');
} else {
update_post_meta($post->ID, '_featured', 'yes');
}
$sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer());
wp_safe_redirect($sendback);
}
示例4: woocommerce_custom_product_columns
//.........这里部分代码省略.........
echo '<div class="row-actions">';
$i = 0;
$action_count = sizeof($actions);
foreach ($actions as $action => $link) {
++$i;
$i == $action_count ? $sep = '' : ($sep = ' | ');
echo "<span class='{$action}'>{$link}{$sep}</span>";
}
echo '</div>';
get_inline_data($post);
/* Custom inline data for woocommerce */
echo '
<div class="hidden" id="woocommerce_inline_' . $post->ID . '">
<div class="sku">' . $product->sku . '</div>
<div class="regular_price">' . $product->regular_price . '</div>
<div class="sale_price">' . $product->sale_price . '</div>
<div class="weight">' . $product->weight . '</div>
<div class="length">' . $product->length . '</div>
<div class="width">' . $product->width . '</div>
<div class="height">' . $product->height . '</div>
<div class="visibility">' . $product->visibility . '</div>
<div class="stock_status">' . $product->stock_status . '</div>
<div class="stock">' . $product->stock . '</div>
<div class="manage_stock">' . $product->manage_stock . '</div>
<div class="featured">' . $product->featured . '</div>
<div class="product_type">' . $product->product_type . '</div>
<div class="product_is_virtual">' . $product->virtual . '</div>
</div>
';
break;
case "sku":
if ($product->get_sku()) {
echo $product->get_sku();
} else {
echo '<span class="na">–</span>';
}
break;
case "product_type":
if ($product->product_type == 'grouped') {
echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Grouped', 'woocommerce') . '"></span>';
} elseif ($product->product_type == 'external') {
echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('External/Affiliate', 'woocommerce') . '"></span>';
} elseif ($product->product_type == 'simple') {
if ($product->is_virtual()) {
echo '<span class="product-type tips virtual" tip="' . __('Virtual', 'woocommerce') . '"></span>';
} elseif ($product->is_downloadable()) {
echo '<span class="product-type tips downloadable" tip="' . __('Downloadable', 'woocommerce') . '"></span>';
} else {
echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Simple', 'woocommerce') . '"></span>';
}
} elseif ($product->product_type == 'variable') {
echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Variable', 'woocommerce') . '"></span>';
} else {
// Assuming that we have other types in future
echo '<span class="product-type tips ' . $product->product_type . '" tip="' . ucwords($product->product_type) . '"></span>';
}
break;
case "price":
if ($product->get_price_html()) {
echo $product->get_price_html();
} else {
echo '<span class="na">–</span>';
}
break;
case "product_cat":
if (!($terms = get_the_term_list($post->ID, 'product_cat', '', ', ', ''))) {
echo '<span class="na">–</span>';
} else {
echo $terms;
}
break;
case "product_tags":
if (!($terms = get_the_term_list($post->ID, 'product_tag', '', ', ', ''))) {
echo '<span class="na">–</span>';
} else {
echo $terms;
}
break;
case "featured":
$url = wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-feature-product&product_id=' . $post->ID), 'woocommerce-feature-product');
echo '<a href="' . $url . '" title="' . __('Change', 'woocommerce') . '">';
if ($product->is_featured()) {
echo '<a href="' . $url . '"><img src="' . $woocommerce->plugin_url() . '/assets/images/featured.png" alt="yes" />';
} else {
echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/featured-off.png" alt="no" />';
}
echo '</a>';
break;
case "is_in_stock":
if ($product->is_in_stock()) {
echo '<mark class="instock">' . __('In stock', 'woocommerce') . '</mark>';
} else {
echo '<mark class="outofstock">' . __('Out of stock', 'woocommerce') . '</mark>';
}
if ($product->managing_stock()) {
echo ' × ' . $product->get_total_stock();
}
break;
}
}
示例5: get_product_data
/**
* Get product data.
*
* @param WC_Product $product Product instance.
* @return array
*/
protected function get_product_data($product)
{
$data = array('id' => $product->get_id(), 'name' => $product->get_name(), 'slug' => $product->get_slug(), 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_date_created()), 'date_modified' => wc_rest_prepare_date_response($product->get_date_modified()), 'type' => $product->get_type(), 'status' => $product->get_status(), 'featured' => $product->is_featured(), 'catalog_visibility' => $product->get_catalog_visibility(), 'description' => wpautop(do_shortcode($product->get_description())), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '', 'date_on_sale_from' => $product->get_date_on_sale_from() ? date('Y-m-d', $product->get_date_on_sale_from()) : '', 'date_on_sale_to' => $product->get_date_on_sale_to() ? date('Y-m-d', $product->get_date_on_sale_to()) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => $product->get_total_sales(), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'external_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'manage_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders' => $product->get_backorders(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'weight' => $product->get_weight(), 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height()), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => $product->get_shipping_class_id(), '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()), 'parent_id' => $product->get_parent_id(), 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->get_purchase_note()))), 'categories' => $this->get_taxonomy_terms($product), 'tags' => $this->get_taxonomy_terms($product, 'tag'), 'images' => $this->get_images($product), 'attributes' => $this->get_attributes($product), 'default_attributes' => $this->get_default_attributes($product), 'variations' => array(), 'grouped_products' => array(), 'menu_order' => $product->get_menu_order());
return $data;
}
示例6: 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() : '';
}
//.........这里部分代码省略.........