<?php
/**
 * Plugin Name: Price & Cart Hider for WooCommerce
 * Plugin URI: https://versesofts.com/product/price-cart-hider-for-woocommerce
 * Description: Hide product prices and the Add to Cart button in WooCommerce based on user roles, countries, or other conditions. Perfect for Catalog Mode, Wholesale, and B2B stores.
 * Version: 1.1.6
 * Tags: hide price, hide cart, WooCommerce price hider, WooCommerce cart hider, price restriction, catalog mode, b2b, wholesale
 * Author: VerseSofts
 * Author URI: https://versesofts.com
 * Author Email: contact@versesofts.com
 * Tested up to: 7.0
 * Text Domain: price-cart-hider-for-woocommerce
 * Requires Plugins: woocommerce
 * WC requires at least: 4.0
 * WC tested up to: 10.4
 * License: GPLv2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 */

defined('ABSPATH') || exit;

define('PCHFW_URL', plugin_dir_url(__FILE__));
define('PCHFW_PATH', plugin_dir_path(__FILE__));
define('PCHFW_FILE', __FILE__);
define('PCHFW_VERSION', '1.1.5');

//Freemius Integration Start
if ( ! function_exists( 'pchfw_fs' ) ) {
    // Create a helper function for easy SDK access.
    function pchfw_fs() {
        global $pchfw_fs;

        if ( ! isset( $pchfw_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/freemius/start.php';

            $pchfw_fs = fs_dynamic_init( array(
                'id'                  => '19253',
                'slug'                => 'price-cart-hider-for-woocommerce',
                'type'                => 'plugin',
                'public_key'          => 'pk_e38e6c2c5f75a41b69efb5e5fc623',
                'is_premium'          => false,
                'has_addons'          => false,
                'has_paid_plans'      => false,
                'menu'                => array(
                    'first-path'     => 'edit.php?post_type=pchfw',
                    'account'        => false,
                    'contact'        => false,
                    'support'        => false,
                    'parent'         => array(
                        'slug' => 'plugins.php',
                    ),
                ),
            ) );
        }

        return $pchfw_fs;
    }

    // Init Freemius.
    pchfw_fs();
    // Signal that SDK was initiated.
    do_action( 'pchfw_fs_loaded' );
}
//Freemius Integration end

if ( ! class_exists( 'Price_Cart_Hider' ) ) {

    class Price_Cart_Hider {

        public function __construct() {

            if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')), true) ) {

                add_action(
                    'before_woocommerce_init', function () {
                        if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class) ) {
                            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
                            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
                        }
                    } 
                );
                $this->includes();

                add_filter('plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'pchfw_settings_link' ));
            } else {
                add_action('admin_notices', array( $this, 'pchfw_inactive_plugin_notice' ));
            }
        }

        public function includes() {
            include_once PCHFW_PATH . '/includes/admin/class-price-cart-hider-admin.php';
            include_once PCHFW_PATH . '/includes/public/class-price-cart-hider-public.php';
            include_once PCHFW_PATH . '/includes/admin/class-price-cart-hider-admin-assets.php';

        }

       public function pchfw_settings_link( $links ) {
            $url = admin_url( 'edit.php?post_type=pchfw' );
            $settings_link = sprintf( '<a href="%s">%s</a>', esc_url( $url ), __( 'Settings', 'price-cart-hider-for-woocommerce' ) );
            array_unshift( $links, $settings_link );
            return $links;
        }

        public function pchfw_inactive_plugin_notice() {
            ?>
            <div class="notice notice-error">
                <p>
                    <?php
                    printf(
                         /* translators: %s: WooCommerce */
                        esc_html__('Price & Cart Hider for WooCommerce requires %s to be installed and active.', 'price-cart-hider-for-woocommerce'),
                        '<a href="https://wordpress.org/plugins/woocommerce/" target="_blank">WooCommerce</a>'
                    );
                    ?>
                </p>
            </div>
            <?php
        }
    }

    new Price_Cart_Hider();

}
