$type->value, self::cases() ); } /** * Settings key for a product (variations use their parent type). * * @param \WC_Product $product Product. * @return string */ public static function key_for( \WC_Product $product ): string { return match ( $product->get_type() ) { 'variation' => self::Variable->value, 'subscription_variation' => self::Variable_Subscription->value, default => (string) $product->get_type(), }; } /** * Label for the admin UI. * * @return string */ public function label(): string { return match ( $this ) { self::Simple => __( 'Simple product', 'add-to-cart-text' ), self::Variable => __( 'Variable product', 'add-to-cart-text' ), self::Grouped => __( 'Grouped product', 'add-to-cart-text' ), self::External => __( 'External/Affiliate product', 'add-to-cart-text' ), self::Subscription => __( 'Simple subscription', 'add-to-cart-text' ), self::Variable_Subscription => __( 'Variable subscription', 'add-to-cart-text' ), self::Booking => __( 'Bookable product', 'add-to-cart-text' ), }; } /** * WooCommerce default text (shown as placeholder in the admin UI). * * @param Context $context Button context. * @return string */ public function default_text( Context $context ): string { $single = Context::Single === $context; return match ( $this ) { self::Simple => __( 'Add to cart', 'add-to-cart-text' ), self::Variable => $single ? __( 'Add to cart', 'add-to-cart-text' ) : __( 'Select options', 'add-to-cart-text' ), self::Grouped => $single ? __( 'Add to cart', 'add-to-cart-text' ) : __( 'View products', 'add-to-cart-text' ), self::External => __( 'Buy product', 'add-to-cart-text' ), self::Subscription => __( 'Sign up now', 'add-to-cart-text' ), self::Variable_Subscription => $single ? __( 'Sign up now', 'add-to-cart-text' ) : __( 'Select options', 'add-to-cart-text' ), self::Booking => $single ? __( 'Book now', 'add-to-cart-text' ) : __( 'Read more', 'add-to-cart-text' ), }; } /** * Whether the extension that provides this type is active. * * @return bool */ public function is_available(): bool { return match ( $this ) { self::Subscription, self::Variable_Subscription => class_exists( 'WC_Subscriptions' ) || class_exists( 'WC_Subscriptions_Core_Plugin' ), self::Booking => class_exists( 'WC_Bookings' ), default => true, }; } }