/
home
/
techb158
/
balacoffee.com
/
wp-content
/
plugins
/
woocommerce
/
includes
/
/home/techb158/balacoffee.com/wp-content/plugins/woocommerce/includes
mkdir
upload
Name
Size
Mode
Actions
abstracts/
-
0755
rm
admin/
-
0755
rm
blocks/
-
0755
rm
cli/
-
0755
rm
customizer/
-
0755
rm
data-stores/
-
0755
rm
emails/
-
0755
rm
export/
-
0755
rm
gateways/
-
0755
rm
import/
-
0755
rm
integrations/
-
0755
rm
interfaces/
-
0755
rm
legacy/
-
0755
rm
libraries/
-
0755
rm
log-handlers/
-
0755
rm
payment-tokens/
-
0755
rm
product-usage/
-
0755
rm
queue/
-
0755
rm
react-admin/
-
0755
rm
rest-api/
-
0755
rm
shipping/
-
0755
rm
shortcodes/
-
0755
rm
theme-support/
-
0755
rm
tracks/
-
0755
rm
traits/
-
0755
rm
walkers/
-
0755
rm
wccom-site/
-
0755
rm
widgets/
-
0755
rm
class-wc-ajax.php
134598
0644
edit
dl
rm
class-wc-auth.php
12995
0644
edit
dl
rm
class-wc-autoloader.php
5394
0644
edit
dl
rm
class-wc-background-emailer.php
4685
0644
edit
dl
rm
class-wc-background-updater.php
3535
0644
edit
dl
rm
class-wc-brands-brand-settings-manager.php
1826
0644
edit
dl
rm
class-wc-brands-coupons.php
7059
0644
edit
dl
rm
class-wc-brands.php
35635
0644
edit
dl
rm
class-wc-breadcrumb.php
10660
0644
edit
dl
rm
class-wc-cache-helper.php
12998
0644
edit
dl
rm
class-wc-cart-fees.php
3448
0644
edit
dl
rm
class-wc-cart-session.php
25975
0644
edit
dl
rm
class-wc-cart-totals.php
29163
0644
edit
dl
rm
class-wc-cart.php
77386
0644
edit
dl
rm
class-wc-checkout.php
51349
0644
edit
dl
rm
class-wc-cli.php
3419
0644
edit
dl
rm
class-wc-comments.php
23631
0644
edit
dl
rm
class-wc-countries.php
51881
0644
edit
dl
rm
class-wc-coupon.php
44920
0644
edit
dl
rm
class-wc-customer-download-log.php
3452
0644
edit
dl
rm
class-wc-customer-download.php
10587
0644
edit
dl
rm
class-wc-customer.php
34000
0644
edit
dl
rm
class-wc-data-exception.php
1321
0644
edit
dl
rm
class-wc-data-store.php
6752
0644
edit
dl
rm
class-wc-datetime.php
2310
0644
edit
dl
rm
class-wc-deprecated-action-hooks.php
6746
0644
edit
dl
rm
class-wc-deprecated-filter-hooks.php
7518
0644
edit
dl
rm
class-wc-discounts.php
37523
0644
edit
dl
rm
class-wc-download-handler.php
29053
0644
edit
dl
rm
class-wc-emails.php
40244
0644
edit
dl
rm
class-wc-embed.php
4342
0644
edit
dl
rm
class-wc-form-handler.php
49327
0644
edit
dl
rm
class-wc-frontend-scripts.php
35185
0644
edit
dl
rm
class-wc-geo-ip.php
31159
0644
edit
dl
rm
class-wc-geolite-integration.php
2036
0644
edit
dl
rm
class-wc-geolocation.php
11615
0644
edit
dl
rm
class-wc-https.php
4439
0644
edit
dl
rm
class-wc-install.php
119017
0644
edit
dl
rm
class-wc-integrations.php
1308
0644
edit
dl
rm
class-wc-log-levels.php
3992
0644
edit
dl
rm
class-wc-logger.php
9639
0644
edit
dl
rm
class-wc-meta-data.php
2260
0644
edit
dl
rm
class-wc-order-factory.php
8951
0644
edit
dl
rm
class-wc-order-item-coupon.php
4175
0644
edit
dl
rm
class-wc-order-item-fee.php
10228
0644
edit
dl
rm
class-wc-order-item-meta.php
5942
0644
edit
dl
rm
class-wc-order-item-product.php
17962
0644
edit
dl
rm
class-wc-order-item-shipping.php
9815
0644
edit
dl
rm
class-wc-order-item-tax.php
6644
0644
edit
dl
rm
class-wc-order-item.php
21907
0644
edit
dl
rm
class-wc-order-query.php
2613
0644
edit
dl
rm
class-wc-order-refund.php
6135
0644
edit
dl
rm
class-wc-order.php
79423
0644
edit
dl
rm
class-wc-payment-gateways.php
14601
0644
edit
dl
rm
class-wc-payment-tokens.php
6390
0644
edit
dl
rm
class-wc-post-data.php
39617
0644
edit
dl
rm
class-wc-post-types.php
33680
0644
edit
dl
rm
class-wc-privacy-background-process.php
1833
0644
edit
dl
rm
class-wc-privacy-erasers.php
13941
0644
edit
dl
rm
class-wc-privacy-exporters.php
15044
0644
edit
dl
rm
class-wc-privacy.php
17629
0644
edit
dl
rm
class-wc-product-attribute.php
8057
0644
edit
dl
rm
class-wc-product-download.php
13494
0644
edit
dl
rm
class-wc-product-external.php
5104
0644
edit
dl
rm
class-wc-product-factory.php
4698
0644
edit
dl
rm
class-wc-product-grouped.php
6974
0644
edit
dl
rm
class-wc-product-query.php
2328
0644
edit
dl
rm
class-wc-product-simple.php
2765
0644
edit
dl
rm
class-wc-product-variable.php
24334
0644
edit
dl
rm
class-wc-product-variation.php
20661
0644
edit
dl
rm
class-wc-query.php
34299
0644
edit
dl
rm
class-wc-rate-limiter.php
4100
0644
edit
dl
rm
class-wc-regenerate-images-request.php
7923
0644
edit
dl
rm
class-wc-regenerate-images.php
15806
0644
edit
dl
rm
class-wc-register-wp-admin-settings.php
5171
0644
edit
dl
rm
class-wc-rest-authentication.php
22068
0644
edit
dl
rm
class-wc-rest-exception.php
276
0644
edit
dl
rm
class-wc-session-handler.php
25162
0644
edit
dl
rm
class-wc-shipping-rate.php
9566
0644
edit
dl
rm
class-wc-shipping-zone.php
13392
0644
edit
dl
rm
class-wc-shipping-zones.php
5115
0644
edit
dl
rm
class-wc-shipping.php
13371
0644
edit
dl
rm
class-wc-shortcodes.php
19274
0644
edit
dl
rm
class-wc-structured-data.php
25011
0644
edit
dl
rm
class-wc-tax.php
40694
0644
edit
dl
rm
class-wc-template-loader.php
20911
0644
edit
dl
rm
class-wc-tracker.php
52731
0644
edit
dl
rm
class-wc-validation.php
5929
0644
edit
dl
rm
class-wc-webhook.php
30807
0644
edit
dl
rm
class-woocommerce.php
63814
0644
edit
dl
rm
wc-account-functions.php
14485
0644
edit
dl
rm
wc-attribute-functions.php
22377
0644
edit
dl
rm
wc-brands-functions.php
4270
0644
edit
dl
rm
wc-cart-functions.php
21308
0644
edit
dl
rm
wc-conditional-functions.php
15902
0644
edit
dl
rm
wc-core-functions.php
80603
0644
edit
dl
rm
wc-coupon-functions.php
5698
0644
edit
dl
rm
wc-deprecated-functions.php
40731
0644
edit
dl
rm
wc-formatting-functions.php
51093
0644
edit
dl
rm
wc-interactivity-api-functions.php
2219
0644
edit
dl
rm
wc-notice-functions.php
8696
0644
edit
dl
rm
wc-order-functions.php
45065
0644
edit
dl
rm
wc-order-item-functions.php
5153
0644
edit
dl
rm
wc-order-step-logger-functions.php
6114
0644
edit
dl
rm
wc-page-functions.php
9657
0644
edit
dl
rm
wc-product-functions.php
68992
0644
edit
dl
rm
wc-rest-functions.php
14268
0644
edit
dl
rm
wc-stock-functions.php
17851
0644
edit
dl
rm
wc-template-functions.php
145476
0644
edit
dl
rm
wc-template-hooks.php
13151
0644
edit
dl
rm
wc-term-functions.php
25158
0644
edit
dl
rm
wc-update-functions.php
104837
0644
edit
dl
rm
wc-user-functions.php
36197
0644
edit
dl
rm
wc-webhook-functions.php
5905
0644
edit
dl
rm
wc-widget-functions.php
2063
0644
edit
dl
rm
Edit:
/home/techb158/balacoffee.com/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php
(24334B)
<?php /** * Variable Product * * The WooCommerce product class handles individual product data. * * @version 3.0.0 * @package WooCommerce\Classes\Products */ use Automattic\WooCommerce\Enums\ProductType; use Automattic\WooCommerce\Enums\ProductStockStatus; defined( 'ABSPATH' ) || exit; /** * Variable product class. */ class WC_Product_Variable extends WC_Product { /** * Array of children variation IDs. Determined by children. * * @var array */ protected $children = null; /** * Array of visible children variation IDs. Determined by children. * * @var array */ protected $visible_children = null; /** * Array of variation attributes IDs. Determined by children. * * @var array */ protected $variation_attributes = null; /** * Get internal type. * * @return string */ public function get_type() { return ProductType::VARIABLE; } /* |-------------------------------------------------------------------------- | Getters |-------------------------------------------------------------------------- */ /** * Get the aria-describedby description for the add to cart button. * Note that this is to provide the description, not the describedby attribute * itself. * * @return string */ public function add_to_cart_aria_describedby() { /** * This filter is documented in includes/abstracts/abstract-wc-product.php. * * @since 7.8.0 */ return apply_filters( 'woocommerce_product_add_to_cart_aria_describedby', $this->is_purchasable() ? __( 'This product has multiple variants. The options may be chosen on the product page', 'woocommerce' ) : '', $this ); } /** * Get the add to cart button text. * * @return string */ public function add_to_cart_text() { return apply_filters( 'woocommerce_product_add_to_cart_text', $this->is_purchasable() ? __( 'Select options', 'woocommerce' ) : __( 'Read more', 'woocommerce' ), $this ); } /** * Get the add to cart button text description - used in aria tags. * * @since 3.3.0 * @return string */ public function add_to_cart_description() { /* translators: %s: Product title */ return apply_filters( 'woocommerce_product_add_to_cart_description', sprintf( __( 'Select options for “%s”', 'woocommerce' ), $this->get_name() ), $this ); } /** * Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale. * * @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes). * @return array Array of RAW prices, regular prices, and sale prices with keys set to variation ID. */ public function get_variation_prices( $for_display = false ) { $prices = $this->data_store->read_price_data( $this, $for_display ); foreach ( $prices as $price_key => $variation_prices ) { $prices[ $price_key ] = $this->sort_variation_prices( $variation_prices ); } return $prices; } /** * Get the min or max variation regular price. * * @param string $min_or_max Min or max price. * @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes). * @return string */ public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) { $prices = $this->get_variation_prices( $for_display ); $price = 'min' === $min_or_max ? current( $prices['regular_price'] ) : end( $prices['regular_price'] ); return apply_filters( 'woocommerce_get_variation_regular_price', $price, $this, $min_or_max, $for_display ); } /** * Get the min or max variation sale price. * * @param string $min_or_max Min or max price. * @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes). * @return string */ public function get_variation_sale_price( $min_or_max = 'min', $for_display = false ) { $prices = $this->get_variation_prices( $for_display ); $price = 'min' === $min_or_max ? current( $prices['sale_price'] ) : end( $prices['sale_price'] ); return apply_filters( 'woocommerce_get_variation_sale_price', $price, $this, $min_or_max, $for_display ); } /** * Get the min or max variation (active) price. * * @param string $min_or_max Min or max price. * @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes). * @return string */ public function get_variation_price( $min_or_max = 'min', $for_display = false ) { $prices = $this->get_variation_prices( $for_display ); $price = 'min' === $min_or_max ? current( $prices['price'] ) : end( $prices['price'] ); return apply_filters( 'woocommerce_get_variation_price', $price, $this, $min_or_max, $for_display ); } /** * Returns the price in html format. * * Note: Variable prices do not show suffixes like other product types. This * is due to some things like tax classes being set at variation level which * could differ from the parent price. The only way to show accurate prices * would be to load the variation and get it's price, which adds extra * overhead and still has edge cases where the values would be inaccurate. * * Additionally, ranges of prices no longer show 'striked out' sale prices * due to the strings being very long and unclear/confusing. A single range * is shown instead. * * @param string $price Price (default: ''). * @return string */ public function get_price_html( $price = '' ) { $prices = $this->get_variation_prices( true ); if ( empty( $prices['price'] ) ) { $price = apply_filters( 'woocommerce_variable_empty_price_html', '', $this ); } else { $min_price = current( $prices['price'] ); $max_price = end( $prices['price'] ); $min_reg_price = current( $prices['regular_price'] ); $max_reg_price = end( $prices['regular_price'] ); if ( $min_price !== $max_price ) { $price = wc_format_price_range( $min_price, $max_price ); } elseif ( $this->is_on_sale() && $min_reg_price === $max_reg_price ) { $price = wc_format_sale_price( wc_price( $max_reg_price ), wc_price( $min_price ) ); } else { $price = wc_price( $min_price ); } $price = apply_filters( 'woocommerce_variable_price_html', $price . $this->get_price_suffix(), $this ); } return apply_filters( 'woocommerce_get_price_html', $price, $this ); } /** * Get the suffix to display after prices > 0. * * This is skipped if the suffix * has dynamic values such as {price_excluding_tax} for variable products. * * @see get_price_html for an explanation as to why. * @param string $price Price to calculate, left blank to just use get_price(). * @param integer $qty Quantity passed on to get_price_including_tax() or get_price_excluding_tax(). * @return string */ public function get_price_suffix( $price = '', $qty = 1 ) { $suffix = get_option( 'woocommerce_price_display_suffix' ); if ( strstr( $suffix, '{' ) ) { return apply_filters( 'woocommerce_get_price_suffix', '', $this, $price, $qty ); } else { return parent::get_price_suffix( $price, $qty ); } } /** * Return a products child ids. * * This is lazy loaded as it's not used often and does require several queries. * * @param bool|string $visible_only Visible only. * @return int[] Children ids */ public function get_children( $visible_only = '' ) { if ( is_bool( $visible_only ) ) { wc_deprecated_argument( 'visible_only', '3.0', 'WC_Product_Variable::get_visible_children' ); return $visible_only ? $this->get_visible_children() : $this->get_children(); } if ( null === $this->children ) { $children = $this->data_store->read_children( $this ); $this->set_children( $children['all'] ); $this->set_visible_children( $children['visible'] ); } return apply_filters( 'woocommerce_get_children', $this->children, $this, false ); } /** * Return a products child ids - visible only. * * This is lazy loaded as it's not used often and does require several queries. * * @since 3.0.0 * @return int[] Children ids */ public function get_visible_children() { if ( null === $this->visible_children ) { $children = $this->data_store->read_children( $this ); $this->set_children( $children['all'] ); $this->set_visible_children( $children['visible'] ); } return apply_filters( 'woocommerce_get_children', $this->visible_children, $this, true ); } /** * Return an array of attributes used for variations, as well as their possible values. * * This is lazy loaded as it's not used often and does require several queries. * * @return array Attributes and their available values */ public function get_variation_attributes() { if ( null === $this->variation_attributes ) { $this->variation_attributes = $this->data_store->read_variation_attributes( $this ); } return $this->variation_attributes; } /** * If set, get the default attributes for a variable product. * * @param string $attribute_name Attribute name. * @return string */ public function get_variation_default_attribute( $attribute_name ) { $defaults = $this->get_default_attributes(); $attribute_name = sanitize_title( $attribute_name ); return isset( $defaults[ $attribute_name ] ) ? $defaults[ $attribute_name ] : ''; } /** * Variable products themselves cannot be downloadable. * * @param string $context What the value is for. Valid values are view and edit. * @return bool */ public function get_downloadable( $context = 'view' ) { return false; } /** * Variable products themselves cannot be virtual. * * @param string $context What the value is for. Valid values are view and edit. * @return bool */ public function get_virtual( $context = 'view' ) { return false; } /** * Get an array of available variations for the current product. * * Important: The default 'array' return type is expensive for products with many variations. * It calls get_available_variation() for each variation, which processes HTML generation * (wc_get_stock_html, get_price_html), price calculations (wc_get_price_to_display), * image attachment lookups, and dimension/weight formatting - all passed through filters. * * Use 'objects' when you only need the WC_Product_Variation objects or a subset of the generated * output of ::get_available_variation(), avoiding unnecessary processing overhead. * * @since 2.4.0 * * @param string $return Optional. The format to return the results in. Default 'array'. * - 'array': Returns fully processed variation data arrays. Each variation * is passed through get_available_variation() which generates HTML, * calculates display prices, and formats dimensions/weights. Use this * when you need the complete variation data for front-end display. * - 'objects': Returns WC_Product_Variation objects directly without * additional processing. Use this when you need to work with variation * objects and will call methods on them selectively. * @return array[]|WC_Product_Variation[] Array of variation data arrays or variation objects. * * @phpstan-param 'array'|'objects' $return * @phpstan-return ($return is 'array' ? array[] : WC_Product_Variation[]) */ public function get_available_variations( $return = 'array' ) { $variation_ids = $this->get_children(); $hide_out_of_stock_items = ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ); $available_variations = array(); if ( ! empty( $variation_ids ) ) { // Prime caches to reduce future queries. _prime_post_caches( $variation_ids ); } foreach ( $variation_ids as $variation_id ) { $variation = wc_get_product( $variation_id ); // Hide out of stock variations if 'Hide out of stock items from the catalog' is checked. if ( ! $variation || ! $variation->exists() || ( $hide_out_of_stock_items && ! $variation->is_in_stock() ) ) { continue; } /** * Filter 'woocommerce_hide_invisible_variations' to optionally hide invisible variations (disabled variations and variations with empty price). * * @since 2.6.8 * * @param bool $hide Whether to hide invisible variations. Default true. * @param int $product_id The ID of the variation. * @param WC_Product_Variation $variation The variation object. */ if ( apply_filters( 'woocommerce_hide_invisible_variations', true, $this->get_id(), $variation ) && ! $variation->variation_is_visible() ) { continue; } if ( 'array' === $return ) { $available_variations[] = $this->get_available_variation( $variation ); } else { $available_variations[] = $variation; } } if ( 'array' === $return ) { $available_variations = array_values( array_filter( $available_variations ) ); } return $available_variations; } /** * Check if there are variations that can be purchased for the current product. * * @internal * * @since 10.0.0 * @return bool */ public function has_purchasable_variations() { $variation_ids = $this->get_children(); if ( ! empty( $variation_ids ) ) { // Prime caches to reduce future queries. _prime_post_caches( $variation_ids ); } foreach ( $variation_ids as $variation_id ) { $variation = wc_get_product( $variation_id ); if ( ! $variation || ! $variation->is_purchasable() || ! $variation->is_in_stock() ) { continue; } // We found at least one available variation, so return true. return true; } // There were either no variations, or they were hidden because of the "continues" above. return false; } /** * Returns an array of data for a variation. Used in the add to cart form. * * @since 2.4.0 * @param WC_Product $variation Variation product object or ID. * @return array|bool */ public function get_available_variation( $variation ) { if ( is_numeric( $variation ) ) { $variation = wc_get_product( $variation ); } if ( ! $variation instanceof WC_Product_Variation ) { return false; } // See if prices should be shown for each variation after selection. $show_variation_price = apply_filters( 'woocommerce_show_variation_price', $variation->get_price() === '' || $this->get_variation_sale_price( 'min' ) !== $this->get_variation_sale_price( 'max' ) || $this->get_variation_regular_price( 'min' ) !== $this->get_variation_regular_price( 'max' ), $this, $variation ); return apply_filters( 'woocommerce_available_variation', array( 'attributes' => $variation->get_variation_attributes(), 'availability_html' => wc_get_stock_html( $variation ), 'backorders_allowed' => $variation->backorders_allowed(), 'dimensions' => $variation->get_dimensions( false ), 'dimensions_html' => wc_format_dimensions( $variation->get_dimensions( false ) ), 'display_price' => wc_get_price_to_display( $variation ), 'display_regular_price' => wc_get_price_to_display( $variation, array( 'price' => $variation->get_regular_price() ) ), 'image' => wc_get_product_attachment_props( $variation->get_image_id() ), 'image_id' => $variation->get_image_id(), 'is_downloadable' => $variation->is_downloadable(), 'is_in_stock' => $variation->is_in_stock(), 'is_purchasable' => $variation->is_purchasable(), 'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no', 'is_virtual' => $variation->is_virtual(), 'max_qty' => 0 < $variation->get_max_purchase_quantity() ? $variation->get_max_purchase_quantity() : '', 'min_qty' => $variation->get_min_purchase_quantity(), 'price_html' => $show_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '', 'sku' => $variation->get_sku(), 'variation_description' => wc_format_content( $variation->get_description() ), 'variation_id' => $variation->get_id(), 'variation_is_active' => $variation->variation_is_active(), 'variation_is_visible' => $variation->variation_is_visible(), 'weight' => $variation->get_weight(), 'weight_html' => wc_format_weight( $variation->get_weight() ), ), $this, $variation ); } /* |-------------------------------------------------------------------------- | Setters |-------------------------------------------------------------------------- */ /** * Sets an array of variation attributes. * * @since 3.0.0 * @param array $variation_attributes Attributes list. */ public function set_variation_attributes( $variation_attributes ) { $this->variation_attributes = $variation_attributes; } /** * Sets an array of children for the product. * * @since 3.0.0 * @param array $children Children products. */ public function set_children( $children ) { $this->children = array_filter( wp_parse_id_list( (array) $children ) ); } /** * Sets an array of visible children only. * * @since 3.0.0 * @param array $visible_children List of visible children products. */ public function set_visible_children( $visible_children ) { $this->visible_children = array_filter( wp_parse_id_list( (array) $visible_children ) ); } /* |-------------------------------------------------------------------------- | CRUD methods |-------------------------------------------------------------------------- */ /** * Ensure properties are set correctly before save. * * @since 3.0.0 */ public function validate_props() { parent::validate_props(); if ( ! $this->get_manage_stock() ) { $this->data_store->sync_stock_status( $this ); } } /** * Do any extra processing needed before the actual product save * (but after triggering the 'woocommerce_before_..._object_save' action) * * @return mixed A state value that will be passed to after_data_store_save_or_update. */ protected function before_data_store_save_or_update() { // Get names before save. $previous_name = $this->data['name']; $new_name = $this->get_name( 'edit' ); return array( 'previous_name' => $previous_name, 'new_name' => $new_name, ); } /** * Do any extra processing needed after the actual product save * (but before triggering the 'woocommerce_after_..._object_save' action) * * @param mixed $state The state object that was returned by before_data_store_save_or_update. */ protected function after_data_store_save_or_update( $state ) { $this->data_store->sync_variation_names( $this, $state['previous_name'], $state['new_name'] ); $this->data_store->sync_managed_variation_stock_status( $this ); } /* |-------------------------------------------------------------------------- | Conditionals |-------------------------------------------------------------------------- */ /** * Returns whether or not the product is on sale. * * @param string $context What the value is for. Valid values are view and edit. What the value is for. Valid values are view and edit. * @return bool */ public function is_on_sale( $context = 'view' ) { $prices = $this->get_variation_prices(); $on_sale = $prices['regular_price'] !== $prices['sale_price'] && $prices['sale_price'] === $prices['price']; return 'view' === $context ? apply_filters( 'woocommerce_product_is_on_sale', $on_sale, $this ) : $on_sale; } /** * Is a child in stock? * * @return boolean */ public function child_is_in_stock() { return $this->data_store->child_is_in_stock( $this ); } /** * Is a child on backorder? * * @since 3.3.0 * @return boolean */ public function child_is_on_backorder() { return $this->data_store->child_has_stock_status( $this, ProductStockStatus::ON_BACKORDER ); } /** * Does a child have a weight set? * * @return boolean */ public function child_has_weight() { $transient_name = 'wc_child_has_weight_' . $this->get_id(); $has_weight = get_transient( $transient_name ); if ( false === $has_weight ) { $has_weight = $this->data_store->child_has_weight( $this ); set_transient( $transient_name, (int) $has_weight, DAY_IN_SECONDS * 30 ); } return (bool) $has_weight; } /** * Does a child have dimensions set? * * @return boolean */ public function child_has_dimensions() { $transient_name = 'wc_child_has_dimensions_' . $this->get_id(); $has_dimension = get_transient( $transient_name ); if ( false === $has_dimension ) { $has_dimension = $this->data_store->child_has_dimensions( $this ); set_transient( $transient_name, (int) $has_dimension, DAY_IN_SECONDS * 30 ); } return (bool) $has_dimension; } /** * Returns whether or not the product has dimensions set. * * @return bool */ public function has_dimensions() { return parent::has_dimensions() || $this->child_has_dimensions(); } /** * Returns whether or not the product has weight set. * * @return bool */ public function has_weight() { return parent::has_weight() || $this->child_has_weight(); } /** * Returns whether or not the product has additional options that need * selecting before adding to cart. * * @since 3.0.0 * @return boolean */ public function has_options() { return apply_filters( 'woocommerce_product_has_options', true, $this ); } /* |-------------------------------------------------------------------------- | Sync with child variations. |-------------------------------------------------------------------------- */ /** * Sync a variable product with its children. These sync functions sync * upwards (from child to parent) when the variation is saved. * * @param WC_Product|int $product Product object or ID for which you wish to sync. * @param bool $save If true, the product object will be saved to the DB before returning it. * @return WC_Product Synced product object. */ public static function sync( $product, $save = true ) { if ( ! is_a( $product, 'WC_Product' ) ) { $product = wc_get_product( $product ); } if ( is_a( $product, 'WC_Product_Variable' ) ) { $data_store = WC_Data_Store::load( 'product-' . $product->get_type() ); $data_store->sync_price( $product ); $data_store->sync_stock_status( $product ); self::sync_attributes( $product ); // Legacy update of attributes. do_action( 'woocommerce_variable_product_sync_data', $product ); if ( $save ) { $product->save(); } wc_do_deprecated_action( 'woocommerce_variable_product_sync', array( $product->get_id(), $product->get_visible_children(), ), '3.0', 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product' ); } return $product; } /** * Sync parent stock status with the status of all children and save. * * @param WC_Product|int $product Product object or ID for which you wish to sync. * @param bool $save If true, the product object will be saved to the DB before returning it. * @return WC_Product Synced product object. */ public static function sync_stock_status( $product, $save = true ) { if ( ! is_a( $product, 'WC_Product' ) ) { $product = wc_get_product( $product ); } if ( is_a( $product, 'WC_Product_Variable' ) ) { $data_store = WC_Data_Store::load( 'product-' . $product->get_type() ); $data_store->sync_stock_status( $product ); if ( $save ) { $product->save(); } } return $product; } /** * Sort an associative array of $variation_id => $price pairs in order of min and max prices. * * @param array $prices associative array of $variation_id => $price pairs. * @return array */ protected function sort_variation_prices( $prices ) { asort( $prices ); return $prices; } }
Save
cmd:
run