<?php
/**
 * WooCommerce Compatibility File
 *
 * @link https://woocommerce.com/
 *
 * @package Zentorone
 */

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

class Zentorone_WooCommerce {

	public function __construct() {
		add_action( 'after_setup_theme', array( $this, 'setup' ) );
        add_action( 'wp_enqueue_scripts', array( $this, 'conditional_wc_assets' ), 99 );
        
        // Remove default Woo styles if not on Woo pages (performance)
        // Note: 'woocommerce_enqueue_styles' filter can be used too.
	}

    /**
     * Conditionally load WooCommerce assets only where needed
     */
    public function conditional_wc_assets() {
        if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
            // Dequeue scripts
            wp_dequeue_script( 'woocommerce' );
            wp_dequeue_script( 'wc-cart-fragments' );
            wp_dequeue_script( 'wc-add-to-cart' );
            wp_dequeue_script( 'wc-checkout' );
            
            // Dequeue styles (if they were enabled)
            wp_dequeue_style( 'woocommerce-general' );
            wp_dequeue_style( 'woocommerce-layout' );
            wp_dequeue_style( 'woocommerce-smallscreen' );
        }
    }

	public function setup() {
		add_theme_support(
			'woocommerce',
			array(
				'thumbnail_image_width' => 150,
				'single_image_width'    => 300,
				'product_grid'          => array(
					'default_rows'    => 3,
					'min_rows'        => 2,
					'max_rows'        => 8,
					'default_columns' => 4,
					'min_columns'     => 2,
					'max_columns'     => 5,
				),
			)
		);

		add_theme_support( 'wc-product-gallery-zoom' );
		add_theme_support( 'wc-product-gallery-lightbox' );
		add_theme_support( 'wc-product-gallery-slider' );
	}
}
