<?php
declare( strict_types=1 );

namespace FiboFilters\Integrations\Plugins;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}


class PwWooCommerceGiftCards extends AbstractPlugin {

	public function init(): void {
		add_filter( 'fibofilters/woocommerce/variations_wrapper_product_types', [ $this, 'add_variations_wrapper_product_type' ] );
	}

	/**
	 * The plugin PW WooCommerce Gift Cards adds their own product type called "PW Gift Card" (pw-gift-card).
	 * It behaves similar to "Variable Product" which is abstract construct (wrapper for variations).
	 * After adding 'pw-gift-card' to variations wrapper product types, we achieve:
	 *
	 * 1. Excluding "PW Gift Card" product type from saving in descriptors. We don't save abstract product in descriptors.
	 * 2. After saving parent products, all variables (gift cards) will be also updated.
	 *
	 * @param array $product_types Excluded product types.
	 */
	public function add_variations_wrapper_product_type( array $product_types ): array {
		$product_types[] = 'pw-gift-card';

		return $product_types;
	}

}
