本文整理汇总了PHP中WC_Product_Variable类的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variable类的具体用法?PHP WC_Product_Variable怎么用?PHP WC_Product_Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_Product_Variable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_varation_save_attributes
function test_varation_save_attributes()
{
// Create a variable product with a color attribute.
$product = new WC_Product_Variable();
$attribute = new WC_Product_Attribute();
$attribute->set_id(0);
$attribute->set_name('color');
$attribute->set_options(explode(WC_DELIMITER, 'green | red'));
$attribute->set_visible(true);
$attribute->set_variation(true);
$product->set_attributes(array($attribute));
$product->save();
// Create a new variation with the color 'green'.
$variation = new WC_Product_Variation();
$variation->set_parent_id($product->get_id());
$variation->set_attributes(array('color' => 'green'));
$variation->set_status('private');
$variation->save();
// Now update some value unrelated to attributes.
$variation = wc_get_product($variation->get_id());
$variation->set_status('publish');
$variation->save();
// Load up the updated variation and verify that the saved state is correct.
$loaded_variation = wc_get_product($variation->get_id());
$this->assertEquals('publish', $loaded_variation->get_status('edit'));
$_attribute = $loaded_variation->get_attributes('edit');
$this->assertEquals('green', $_attribute['color']);
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:28,代码来源:data-store.php
示例2: array
/**
* Use it to avoid repeated get_child calls for the same variation.
*
* @param int $variation_id
* @param WC_Product_Variable $product
* @return WC_Product_Variation
*/
function get_variation($variation_id, $product)
{
if (isset($this->variations_cache[$variation_id])) {
return $this->variations_cache[$variation_id];
}
$variation = $product->get_child($variation_id, array('parent_id' => $product->id, 'parent' => $product));
$this->variations_cache[$variation_id] = $variation;
return $variation;
}
开发者ID:ajay786singh,项目名称:viriditas-1,代码行数:16,代码来源:class-wc-pb-helpers.php
示例3: filter_custom_fields
/**
* Add woo attributes to a custom field with the same name
*
* @param $custom_fields
* @param $post_id
*
* @return mixed
*/
public function filter_custom_fields($custom_fields, $post_id)
{
if (!isset($custom_fields)) {
$custom_fields = array();
}
// Get the product correponding to this post
$product = wc_get_product($post_id);
if (false === $product) {
// Not a product
return $custom_fields;
}
switch ($product->get_type()) {
case self::PRODUCT_TYPE_VARIABLE:
$product_variable = new WC_Product_Variable($product);
foreach ($product_variable->get_available_variations() as $variation_array) {
foreach ($variation_array['attributes'] as $attribute_name => $attribute_value) {
if (!isset($custom_fields[$attribute_name])) {
$custom_fields[$attribute_name] = array();
}
if (!in_array($attribute_value, $custom_fields[$attribute_name], true)) {
array_push($custom_fields[$attribute_name], $attribute_value);
}
}
}
break;
default:
foreach ($product->get_attributes() as $attribute) {
//$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
// Remove the eventual 'pa_' prefix from the global attribute name
$attribute_name = $attribute['name'];
if (substr($attribute_name, 0, 3) === 'pa_') {
$attribute_name = substr($attribute_name, 3, strlen($attribute_name));
}
$custom_fields[$attribute_name] = explode(',', $product->get_attribute($attribute['name']));
}
break;
}
return $custom_fields;
}
开发者ID:silvestrelosada,项目名称:wpsolr-search-engine,代码行数:47,代码来源:plugin-woocommerce.php
示例4: wcva_return_displaytype_number
function wcva_return_displaytype_number($product, $post)
{
$displaytypenumber = 0;
$product = get_product($post->ID);
$_coloredvariables = get_post_meta($product->id, '_coloredvariables', true);
$displaytype = "none";
if ($product->product_type == 'variable') {
$product = new WC_Product_Variable($post->ID);
$attributes = $product->get_variation_attributes();
}
if (!empty($attributes) && sizeof($attributes) > 0) {
foreach ($attributes as $key => $values) {
if (isset($_coloredvariables[$key]['display_type'])) {
$displaytype = $_coloredvariables[$key]['display_type'];
}
if ($displaytype == "colororimage" || $displaytype == "radio") {
$displaytypenumber++;
}
}
}
return $displaytypenumber;
}
开发者ID:rinodung,项目名称:live-theme,代码行数:22,代码来源:wcva_common_functions.php
示例5: product_page_pricing_table
/**
* Maybe display pricing table or anchor to display pricing table in modal
*
* @access public
* @return void
*/
public function product_page_pricing_table()
{
if ($this->opt['settings']['display_table'] == 'hide' && (!isset($this->opt['settings']['display_offers']) || $this->opt['settings']['display_offers'] == 'hide')) {
return;
}
global $product;
if (!$product) {
return;
}
// Load required classes
require_once RP_WCDPD_PLUGIN_PATH . 'includes/classes/Pricing.php';
$selected_rule = null;
// Iterate over pricing rules and use the first one that has this product in conditions (or does not have if condition "not in list")
if (isset($this->opt['pricing']['sets']) && count($this->opt['pricing']['sets'])) {
foreach ($this->opt['pricing']['sets'] as $rule_key => $rule) {
if ($rule['method'] == 'quantity' && ($validated_rule = RP_WCDPD_Pricing::validate_rule($rule))) {
if ($validated_rule['selection_method'] == 'all' && $this->user_matches_rule($validated_rule)) {
$selected_rule = $validated_rule;
break;
}
if ($validated_rule['selection_method'] == 'categories_include' && count(array_intersect($this->get_product_categories($product->id), $validated_rule['categories'])) > 0 && $this->user_matches_rule($validated_rule)) {
$selected_rule = $validated_rule;
break;
}
if ($validated_rule['selection_method'] == 'categories_exclude' && count(array_intersect($this->get_product_categories($product->id), $validated_rule['categories'])) == 0 && $this->user_matches_rule($validated_rule)) {
$selected_rule = $validated_rule;
break;
}
if ($validated_rule['selection_method'] == 'products_include' && in_array($product->id, $validated_rule['products']) && $this->user_matches_rule($validated_rule)) {
$selected_rule = $validated_rule;
break;
}
if ($validated_rule['selection_method'] == 'products_exclude' && !in_array($product->id, $validated_rule['products']) && $this->user_matches_rule($validated_rule)) {
$selected_rule = $validated_rule;
break;
}
}
}
}
if (is_array($selected_rule)) {
// Quantity
if ($selected_rule['method'] == 'quantity' && in_array($this->opt['settings']['display_table'], array('modal', 'inline')) && isset($selected_rule['pricing'])) {
if ($product->product_type == 'variable') {
$product_variations = $product->get_available_variations();
}
// For variable products only - check if prices differ for different variations
$multiprice_variable_product = false;
if ($product->product_type == 'variable' && !empty($product_variations)) {
$last_product_variation = array_slice($product_variations, -1);
$last_product_variation_object = new WC_Product_Variable($last_product_variation[0]['variation_id']);
$last_product_variation_price = $last_product_variation_object->get_price();
foreach ($product_variations as $variation) {
$variation_object = new WC_Product_Variable($variation['variation_id']);
if ($variation_object->get_price() != $last_product_variation_price) {
$multiprice_variable_product = true;
}
}
}
if ($multiprice_variable_product) {
$variation_table_data = array();
foreach ($product_variations as $variation) {
$variation_product = new WC_Product_Variation($variation['variation_id']);
$variation_table_data[$variation['variation_id']] = $this->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
}
require_once RP_WCDPD_PLUGIN_PATH . 'includes/views/frontend/table-variable.php';
} else {
if ($product->product_type == 'variable' && !empty($product_variations)) {
$variation_product = new WC_Product_Variation($last_product_variation[0]['variation_id']);
$table_data = $this->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
} else {
$table_data = $this->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $product->get_price());
}
require_once RP_WCDPD_PLUGIN_PATH . 'includes/views/frontend/table-' . $this->opt['settings']['display_table'] . '-' . $this->opt['settings']['pricing_table_style'] . '.php';
}
}
}
}
开发者ID:baden03,项目名称:access48,代码行数:83,代码来源:wc-dynamic-pricing-and-discounts.php
示例6: 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;
//.........这里部分代码省略.........
开发者ID:vkolova,项目名称:bgscena,代码行数:101,代码来源:class-wc-admin-post-types.php
示例7: fixVariableStockStatus
public function fixVariableStockStatus()
{
// get all parent variations
$args = array('post_type' => 'product', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('variable'))));
$query = new WP_Query($args);
$parent_variations = $query->posts;
// loop products
foreach ($parent_variations as $post) {
// $this->fixVariableStockStatusForProduct( $post->ID );
WC_Product_Variable::sync_stock_status($post->ID);
}
}
开发者ID:imranshuvo,项目名称:wp-lister-for-amazon,代码行数:12,代码来源:ToolsPage.php
示例8: variable_product_sync
/**
* Sync variable product prices with the children lowest/highest price per
* unit.
*
* Code based on WC_Product_Variable version 2.0.0
* @see WC_Product_Variable::variable_product_sync()
* @see WC_Price_Calculator_Product::variable_product_unsync()
*
* @since 3.0
* @param WC_Product_Variable $product the variable product
* @param WC_Price_Calculator_Settings $settings the calculator settings
*/
public static function variable_product_sync($product, $settings)
{
// save the original values so we can restore the product
$product->wcmpc_min_variation_price = $product->min_variation_price;
$product->wcmpc_min_variation_regular_price = $product->min_variation_regular_price;
$product->wcmpc_min_variation_sale_price = $product->min_variation_sale_price;
$product->wcmpc_max_variation_price = $product->max_variation_price;
$product->wcmpc_max_variation_regular_price = $product->max_variation_regular_price;
$product->wcmpc_max_variation_sale_price = $product->max_variation_sale_price;
$product->wcmpc_price = $product->price;
$product->min_variation_price = $product->min_variation_regular_price = $product->min_variation_sale_price = $product->max_variation_price = $product->max_variation_regular_price = $product->max_variation_sale_price = '';
foreach ($product->get_children() as $variation_product_id) {
$variation_product = apply_filters('wc_measurement_price_calculator_variable_product_sync', SV_WC_Plugin_Compatibility::wc_get_product($variation_product_id), $product);
$child_price = $variation_product->price;
$child_regular_price = $variation_product->regular_price;
$child_sale_price = $variation_product->sale_price;
// get the product measurement
$measurement = self::get_product_measurement($variation_product, $settings);
$measurement->set_unit($settings->get_pricing_unit());
if ('' === $child_price && '' === $child_regular_price || !$measurement->get_value()) {
continue;
}
// convert to price per unit
if ('' !== $child_price) {
$child_price /= $measurement->get_value();
}
// Regular prices
if ($child_regular_price !== '') {
// convert to price per unit
$child_regular_price /= $measurement->get_value();
if (!is_numeric($product->min_variation_regular_price) || $child_regular_price < $product->min_variation_regular_price) {
$product->min_variation_regular_price = $child_regular_price;
}
if (!is_numeric($product->max_variation_regular_price) || $child_regular_price > $product->max_variation_regular_price) {
$product->max_variation_regular_price = $child_regular_price;
}
}
// Sale prices
if ($child_sale_price !== '') {
// convert to price per unit
$child_sale_price /= $measurement->get_value();
if ($child_price == $child_sale_price) {
if (!is_numeric($product->min_variation_sale_price) || $child_sale_price < $product->min_variation_sale_price) {
$product->min_variation_sale_price = $child_sale_price;
}
if (!is_numeric($product->max_variation_sale_price) || $child_sale_price > $product->max_variation_sale_price) {
$product->max_variation_sale_price = $child_sale_price;
}
}
}
// Actual prices
if ($child_price !== '') {
if ($child_price > $product->max_variation_price) {
$product->max_variation_price = $child_price;
}
if ($product->min_variation_price === '' || $child_price < $product->min_variation_price) {
$product->min_variation_price = $child_price;
}
}
}
// as seen in WC_Product_Variable::get_price_html()
$product->price = $product->min_variation_price;
}
开发者ID:abcode619,项目名称:wpstuff,代码行数:75,代码来源:class-wc-price-calculator-product.php
示例9: bulk_edit_variations
//.........这里部分代码省略.........
case 'variable_width':
case 'variable_height':
if (empty($data['value'])) {
break;
}
$value = wc_clean($data['value']);
$field = str_replace('variable', '', $bulk_action);
$wpdb->query($wpdb->prepare("\n\t\t\t\t\tUPDATE {$wpdb->postmeta} AS postmeta\n\t\t\t\t\tINNER JOIN {$wpdb->posts} AS posts ON posts.post_parent = %d\n\t\t\t\t\tSET postmeta.meta_value = %s\n\t\t\t\t\tWHERE postmeta.meta_key = '%s'\n\t\t\t\t\tAND postmeta.post_id = posts.ID\n\t\t\t\t ", $product_id, $value, $field));
break;
case 'variable_download_limit':
case 'variable_download_expiry':
if (empty($data['value'])) {
break;
}
$value = wc_clean($data['value']);
$field = str_replace('variable', '', $bulk_action);
foreach ($variations as $variation_id) {
if ('yes' === get_post_meta($variation_id, '_downloadable', true)) {
update_post_meta($variation_id, $field, $value);
} else {
update_post_meta($variation_id, $field, '');
}
}
break;
case 'delete_all':
if (isset($data['allowed']) && 'true' === $data['allowed']) {
foreach ($variations as $variation_id) {
wp_delete_post($variation_id);
}
}
break;
case 'variable_regular_price_increase':
case 'variable_regular_price_decrease':
case 'variable_sale_price_increase':
case 'variable_sale_price_decrease':
if (empty($data['value'])) {
break;
}
$field = str_replace(array('variable', '_increase', '_decrease'), '', $bulk_action);
$operator = 'increase' === substr($bulk_action, -8) ? +1 : -1;
foreach ($variations as $variation_id) {
// Price fields
$regular_price = get_post_meta($variation_id, '_regular_price', true);
$sale_price = get_post_meta($variation_id, '_sale_price', true);
// Date fields
$date_from = get_post_meta($variation_id, '_sale_price_dates_from', true);
$date_to = get_post_meta($variation_id, '_sale_price_dates_to', true);
$date_from = !empty($date_from) ? date('Y-m-d', $date_from) : '';
$date_to = !empty($date_to) ? date('Y-m-d', $date_to) : '';
if ('%' === substr($data['value'], -1)) {
$percent = wc_format_decimal(substr($data['value'], 0, -1));
if ('_regular_price' === $field) {
$regular_price += $regular_price / 100 * $percent * $operator;
} else {
$sale_price += $sale_price / 100 * $percent * $operator;
}
} else {
if ('_regular_price' === $field) {
$regular_price += $data['value'];
} else {
$sale_price += $data['value'];
}
}
_wc_save_product_price($variation_id, $regular_price, $sale_price, $date_from, $date_to);
}
break;
case 'variable_sale_schedule':
if (!isset($data['date_from']) && !isset($data['date_to'])) {
break;
}
foreach ($variations as $variation_id) {
// Price fields
$regular_price = get_post_meta($variation_id, '_regular_price', true);
$sale_price = get_post_meta($variation_id, '_sale_price', true);
// Date fields
$date_from = get_post_meta($variation_id, '_sale_price_dates_from', true);
$date_to = get_post_meta($variation_id, '_sale_price_dates_to', true);
if ('false' === $data['date_from']) {
$date_from = !empty($date_from) ? date('Y-m-d', $date_from) : '';
} else {
$date_from = $data['date_from'];
}
if ('false' === $data['date_to']) {
$date_to = !empty($date_to) ? date('Y-m-d', $date_to) : '';
} else {
$date_to = $data['date_to'];
}
_wc_save_product_price($variation_id, $regular_price, $sale_price, $date_from, $date_to);
}
break;
default:
do_action('woocommerce_bulk_edit_variations_default', $bulk_action, $data, $product_id, $variations);
break;
}
do_action('woocommerce_bulk_edit_variations', $bulk_action, $data, $product_id, $variations);
// Sync and update transients
WC_Product_Variable::sync($product_id);
wc_delete_product_transients($product_id);
die;
}
开发者ID:nayemDevs,项目名称:woocommerce,代码行数:101,代码来源:class-wc-ajax.php
示例10: woocomposer_list_shortcode
//.........这里部分代码省略.........
$display_type = '';
}
if (!isset($columns)) {
$columns = '4';
}
if (isset($per_page)) {
$post_count = $per_page;
}
if (isset($number)) {
$post_count = $number;
}
if (!isset($order)) {
$order = 'ASC';
}
if (!isset($orderby)) {
$orderby = 'date';
}
if (!isset($category)) {
$category = '';
}
if (!isset($ids)) {
$ids = '';
}
if ($ids) {
$ids = explode(',', $ids);
$ids = array_map('trim', $ids);
}
if ($columns == "2") {
$columns = 6;
} elseif ($columns == "3") {
$columns = 4;
} elseif ($columns == "4") {
$columns = 3;
}
$meta_query = '';
if ($display_type == "recent_products") {
$meta_query = WC()->query->get_meta_query();
}
if ($display_type == "featured_products") {
$meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes'));
}
if ($display_type == "top_rated_products") {
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' => $post_count, 'orderby' => $orderby, 'order' => $order, 'meta_query' => $meta_query);
if ($display_type == "sale_products") {
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
$meta_query = array();
$meta_query[] = $woocommerce->query->visibility_meta_query();
$meta_query[] = $woocommerce->query->stock_status_meta_query();
$args['meta_query'] = $meta_query;
$args['post__in'] = $product_ids_on_sale;
}
if ($display_type == "best_selling_products") {
$args['meta_key'] = 'total_sales';
$args['orderby'] = 'meta_value_num';
$args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'));
}
if ($display_type == "product_category") {
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN'));
}
if ($display_type == "product_categories") {
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => $ids, 'field' => 'term_id', 'operator' => 'IN'));
}
$query = new WP_Query($args);
$output .= '<ul class="wcmp-product-list wcmp-img-' . $img_position . ' ' . $order . '">';
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product_id = get_the_ID();
$post = get_post($product_id);
$product_title = get_the_title();
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$rating = $product->get_rating_html();
$product_var = new WC_Product_Variable($product_id);
$available_variations = $product_var->get_available_variations();
$output .= '<li>';
$output .= '<a href="' . get_permalink($product_id) . '">';
$product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), 'full');
$output .= '<img style="' . $style . '" src="' . $product_img[0] . '"/>';
$output .= '<span style="' . $title_style . '">' . $product_title . '</span>';
$output .= '</a>';
if ($display_type == "top_rated_products") {
$output .= '<div style="' . $rating_style . '">' . $rating . '</div>';
}
$output .= '<span class="amount" style="' . $pricing_style . '">' . $price . '</span>';
$output .= '</li>';
}
}
$output .= "\n" . '</ul>';
$output .= "\n" . '</div>';
if ($display_type == "top_rated_products") {
remove_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
}
wp_reset_postdata();
return $output;
}
开发者ID:ksingh812,项目名称:epb,代码行数:101,代码来源:shortcode_list.php
示例11: set_stock_status
/**
* set_stock_status function.
*/
public function set_stock_status($status)
{
$status = 'outofstock' === $status ? 'outofstock' : 'instock';
// Sanity check
if (true === $this->managing_stock()) {
if (!$this->backorders_allowed() && $this->get_stock_quantity() <= get_option('woocommerce_notify_no_stock_amount')) {
$status = 'outofstock';
}
} elseif ('parent' === $this->managing_stock()) {
if (!$this->parent->backorders_allowed() && $this->parent->get_stock_quantity() <= get_option('woocommerce_notify_no_stock_amount')) {
$status = 'outofstock';
}
}
if (update_post_meta($this->variation_id, '_stock_status', $status)) {
do_action('woocommerce_variation_set_stock_status', $this->variation_id, $status);
if (true === $this->managing_stock()) {
WC_Product_Variable::sync_stock_status($this->id);
}
}
}
开发者ID:noman1059,项目名称:woocommerce,代码行数:23,代码来源:class-wc-product-variation.php
示例12: get_product_from_post
private function get_product_from_post($post_id)
{
$woocommerce_ver_below_2_1 = false;
if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) {
$woocommerce_ver_below_2_1 = true;
}
if ($woocommerce_ver_below_2_1) {
$product = new WC_Product_Simple($post_id);
} else {
$product = new WC_Product($post_id);
}
//$post_categories = wp_get_post_categories( $post_id );
//$categories = get_the_category();
try {
$thumbnail = $product->get_image();
if ($thumbnail) {
if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
$thumbnail = $match[1];
} else {
if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) {
$thumbnail = $match[1];
} else {
if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
// Animate Lazy Load Wordpress Plugin
$thumbnail = $match[1];
} else {
if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) {
$thumbnail = $match[1];
} else {
preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result);
$thumbnail = array_pop($result);
}
}
}
}
}
} catch (Exception $e) {
$err_msg = "exception raised in thumbnails";
self::send_error_report($err_msg);
$thumbnail = '';
}
// handling scheduled sale price update
if (!$woocommerce_ver_below_2_1) {
$sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
$sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
if ($sale_price_dates_from || $sale_price_dates_to) {
self::schedule_sale_price_update($post_id, null);
}
if ($sale_price_dates_from) {
self::schedule_sale_price_update($post_id, $sale_price_dates_from);
}
if ($sale_price_dates_to) {
self::schedule_sale_price_update($post_id, $sale_price_dates_to);
}
}
$product_tags = array();
foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) {
$product_tags[] = $tag->name;
}
$product_brands = array();
if (taxonomy_exists('product_brand')) {
foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) {
$product_brands[] = $brand->name;
}
}
$taxonomies = array();
try {
$all_taxonomies = get_option('wcis_taxonomies');
if (is_array($all_taxonomies)) {
foreach ($all_taxonomies as $taxonomy) {
if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) {
foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) {
if (!array_key_exists($taxonomy, $taxonomies)) {
$taxonomies[$taxonomy] = array();
}
$taxonomies[$taxonomy][] = $taxonomy_value->name;
}
}
}
}
} catch (Exception $e) {
}
$acf_fields = array();
try {
if (class_exists('acf') && function_exists('get_field')) {
$all_acf_fields = get_option('wcis_acf_fields');
if (is_array($all_acf_fields)) {
foreach ($all_acf_fields as $acf_field_name) {
$acf_field_value = get_field($acf_field_name, $post_id);
if ($acf_field_value) {
$acf_fields[$acf_field_name] = $acf_field_value;
}
}
}
}
} catch (Exception $e) {
}
$send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
try {
$variable = new WC_Product_Variable($post_id);
//.........这里部分代码省略.........
开发者ID:booklein,项目名称:wpbookle,代码行数:101,代码来源:wcis_plugin.php
示例13: dispatch
//.........这里部分代码省略.........
}
break;
case 3:
// Check access - cannot use nonce here as it will expire after multiple requests
if (!current_user_can('manage_woocommerce')) {
die;
}
add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
if (function_exists('gc_enable')) {
gc_enable();
}
@set_time_limit(0);
@ob_flush();
@flush();
$wpdb->hide_errors();
$file = stripslashes($_POST['file']);
$mapping = json_decode(stripslashes($_POST['mapping']), true);
$start_pos = isset($_POST['start_pos']) ? absint($_POST['start_pos']) : 0;
$end_pos = isset($_POST['end_pos']) ? absint($_POST['end_pos']) : '';
$position = $this->import_start($file, $mapping, $start_pos, $end_pos);
$this->import();
$this->import_end();
$results = array();
$results['import_results'] = $this->import_results;
$results['processed_terms'] = $this->processed_terms;
$results['processed_posts'] = $this->processed_posts;
$results['post_orphans'] = $this->post_orphans;
$results['attachments'] = $this->attachments;
$results['upsell_skus'] = $this->upsell_skus;
$results['crosssell_skus'] = $this->crosssell_skus;
echo "<!--WC_START-->";
echo json_encode($results);
echo "<!--WC_END-->";
exit;
break;
case 4:
// Check access - cannot use nonce here as it will expire after multiple requests
if (!current_user_can('manage_woocommerce')) {
die;
}
add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
if (function_exists('gc_enable')) {
gc_enable();
}
@set_time_limit(0);
@ob_flush();
@flush();
$wpdb->hide_errors();
$this->processed_terms = isset($_POST['processed_terms']) ? $_POST['processed_terms'] : array();
$this->processed_posts = isset($_POST['processed_posts']) ? $_POST['processed_posts'] : array();
$this->post_orphans = isset($_POST['post_orphans']) ? $_POST['post_orphans'] : array();
$this->crosssell_skus = isset($_POST['crosssell_skus']) ? array_filter((array) $_POST['crosssell_skus']) : array();
$this->upsell_skus = isset($_POST['upsell_skus']) ? array_filter((array) $_POST['upsell_skus']) : array();
_e('Cleaning up...', 'wc_csv_import') . ' ';
wp_defer_term_counting(true);
wp_defer_comment_counting(true);
_e('Clearing transients...', 'wc_csv_import') . ' ';
echo 'Reticulating Splines...' . ' ';
// Easter egg
// reset transients for products
if (function_exists('wc_delete_product_transients')) {
wc_delete_product_transients();
} else {
$woocommerce->clear_product_transients();
}
delete_transient('wc_attribute_taxonomies');
$wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_wc_product_type_%')");
_e('Backfilling parents...', 'wc_csv_import') . ' ';
$this->backfill_parents();
if (!empty($this->upsell_skus)) {
_e('Linking upsells...', 'wc_csv_import') . ' ';
foreach ($this->upsell_skus as $post_id => $skus) {
$this->link_product_skus('upsell', $post_id, $skus);
}
}
if (!empty($this->crosssell_skus)) {
_e('Linking crosssells...', 'wc_csv_import') . ' ';
foreach ($this->crosssell_skus as $post_id => $skus) {
$this->link_product_skus('crosssell', $post_id, $skus);
}
}
if ('woocommerce_variation_csv' == $this->import_page && !empty($this->processed_posts)) {
_e('Syncing variations...', 'wc_csv_import') . ' ';
$synced = array();
foreach ($this->processed_posts as $post_id) {
$parent = wp_get_post_parent_id($post_id);
if (!in_array($parent, $synced)) {
WC_Product_Variable::sync($parent);
$synced[] = $parent;
}
}
}
// SUCCESS
_e('Finished. Import complete.', 'wc_csv_import');
$this->import_end();
exit;
break;
}
$this->footer();
}
开发者ID:Brandonsmith23,项目名称:behind,代码行数:101,代码来源:class-wc-pcsvis-product-import.php
示例14: foreach
}
/* update _price with sale price */
$rows = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_value !='' AND meta_key = %s", $pre_meta_key . '_sale_price'));
foreach ($rows as $row) {
update_post_meta($row->post_id, $pre_meta_key . '_price', $row->meta_value);
}
}
}
/* rename options regions */
delete_option('_oga_wppbc_countries_groups');
add_option('wc_price_based_country_regions', $regions);
/* sync variable products */
require_once WC()->plugin_path() . '/includes/class-wc-product-variable.php';
$rows = $wpdb->get_results($wpdb->prepare("SELECT distinct post_parent FROM {$wpdb->posts} where post_type = %s", 'product_variation'));
foreach ($rows as $row) {
WC_Product_Variable::sync($row->post_parent);
}
/* rename and update test options */
add_option('wc_price_based_country_test_mode', get_option('wc_price_based_country_debug_mode'));
delete_option('wc_price_based_country_debug_mode');
$test_ip = get_option('wc_price_based_country_debug_ip');
if ($test_ip) {
$country = WC_Geolocation::geolocate_ip($test_ip);
add_option('wc_price_based_country_test_country', $country['country']);
}
delete_option('wc_price_based_country_debug_ip');
/* unschedule geoip donwload */
if (wp_next_scheduled('wcpbc_update_geoip')) {
wp_clear_scheduled_hook('wcpbc_update_geoip');
}
delete_option('wc_price_based_country_update_geoip');
开发者ID:raminabsari,项目名称:phonicsschool,代码行数:31,代码来源:wcpbc-update-1.3.2.php
示例15: update_post_meta_fields
/**
* Update post meta fields.
*
* @param WP_Post $post
* @param WP_REST_Request $request
* @return bool|WP_Error
*/
protected function update_post_meta_fields($post, $request)
{
try {
$product = wc_get_product($post);
// Check for featured/gallery images, upload it and set it.
if (isset($request['images'])) {
$this->save_product_images($product->id, $request['
|
请发表评论