本文整理汇总了PHP中WC_Product_Variable::get_total_stock方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variable::get_total_stock方法的具体用法?PHP WC_Product_Variable::get_total_stock怎么用?PHP WC_Product_Variable::get_total_stock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product_Variable
的用法示例。
在下文中一共展示了WC_Product_Variable::get_total_stock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_product_from_post
//.........这里部分代码省略.........
}
}
}
} 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);
$variations = $variable->get_available_variations();
$variations_sku = '';
if (!empty($variations)) {
foreach ($variations as $variation) {
if ($product->get_sku() != $variation['sku']) {
$variations_sku .= $variation['sku'] . ' ';
}
}
}
$send_product['variations_sku'] = $variations_sku;
$all_attributes = $product->get_attributes();
$attributes = array();
if (!empty($all_attributes)) {
foreach ($all_attributes as $attr_mame => $value) {
if ($all_attributes[$attr_mame]['is_taxonomy']) {
if (!$woocommerce_ver_below_2_1) {
$attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names'));
} else {
$attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names');
}
} else {
$attributes[$attr_mame] = $product->get_attribute($attr_mame);
}
}
}
$send_product['attributes'] = $attributes;
$send_product['total_variable_stock'] = $variable->get_total_stock();
try {
if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
if (function_exists('wc_get_product')) {
$original_product = wc_get_product($product->id);
if (is_object($original_product)) {
$send_product['visibility'] = $original_product->is_visible();
$send_product['product_type'] = $original_product->product_type;
}
}
} else {
if (function_exists('get_product')) {
$original_product = get_product($product->id);
if (is_object($original_product)) {
$send_product['visibility'] = $original_product->is_visible();
$send_product['product_type'] = $original_product->product_type;
}
}
}
} catch (Exception $e) {
}
} catch (Exception $e) {
$err_msg = "exception raised in attributes";
self::send_error_report($err_msg);
}
if (!$woocommerce_ver_below_2_1) {
try {
$send_product['price_compare_at_price'] = $product->get_regular_price();
$send_product['price_min'] = $variable->get_variation_price('min');
$send_product['price_max'] = $variable->get_variation_price('max');
$send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min');
$send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max');
} catch (Exception $e) {
$send_product['price_compare_at_price'] = null;
$send_product['price_min'] = null;
$send_product['price_max'] = null;
$send_product['price_min_compare_at_price'] = null;
$send_product['price_max_compare_at_price'] = null;
}
} else {
$send_product['price_compare_at_price'] = null;
$send_product['price_min'] = null;
$send_product['price_max'] = null;
$send_product['price_min_compare_at_price'] = null;
$send_product['price_max_compare_at_price'] = null;
}
$send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']);
$send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']);
$send_product['description'] = self::content_filter_shortcode($send_product['description']);
$send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']);
try {
if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) {
if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
$language_info = apply_filters('wpml_post_language_details', NULL, $post_id);
} else {
$language_info = wpml_get_language_information($post_id);
}
if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) {
// WP_Error could be returned from wpml_get_language_information(...)
$send_product['lang'] = $language_info['locale'];
}
}
} catch (Exception $e) {
}
return $send_product;
}