| Server IP : 5.129.245.98 / Your IP : 216.73.216.246 Web Server : Apache/2.4.66 (Debian) System : Linux 1b8c17c336b9 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/plugins/woocommerce/src/Blocks/Utils/ |
Upload File : |
<?php
declare(strict_types=1);
namespace Automattic\WooCommerce\Blocks\Utils;
use Automattic\WooCommerce\Blocks\Templates\ProductStockIndicator;
use Automattic\WooCommerce\Enums\ProductType;
/**
* Utility functions for product availability.
*/
class ProductAvailabilityUtils {
/**
* Get product availability information.
*
* @param \WC_Product $product Product object.
* @return string[] The product availability class and text.
*/
public static function get_product_availability( $product ) {
$product_availability = array(
'availability' => '',
'class' => '',
);
if ( ! $product ) {
return $product_availability;
}
$product_availability = $product->get_availability();
// If the product is a variable product, make sure at least one of its
// variations is purchasable.
if (
isset( $product_availability['class'] ) &&
( 'in-stock' === $product_availability['class'] || 'available-on-backorder' === $product_availability['class'] ) &&
ProductType::VARIABLE === $product->get_type()
) {
if ( ! $product->has_purchasable_variations() ) {
$product_availability['availability'] = __( 'Out of stock', 'woocommerce' );
$product_availability['class'] = 'out-of-stock';
}
}
return $product_availability;
}
}