
<center><h2><strong>Ubuntu</strong></h2>
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

defined('ABSPATH') || exit;

class WC_Settings_Addify_Advance_Product_Quantity extends WC_Settings_Page {

	/**
	 * Constructor
	 */
	public function __construct() {

		$this->id = 'afadvqty';

		add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 50 );
		add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
		add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
		add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
	}

	/**
	 * Add plugin options tab
	 *
	 * @return array
	 */
	public function add_settings_tab( $settings_tabs ) {
		$settings_tabs[ $this->id ] = __( 'Advance Product Quantity', 'addify-product-qty' );
		return $settings_tabs;
	}

	/**
	 * Get sections
	 *
	 * @return array
	 */
	public function get_sections() {

		$sections = array(
			''                => __( 'Configurations', 'addify-product-qty' ),
			'cart-quantities' => __( 'Cart Quantities', 'addify-product-qty' ),
		);

		return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
	}


	/**
	 * Get sections
	 *
	 * @return array
	 */
	public function get_settings( $section = null, $settings = null ) {

		$settings = array();

		$custom_attributes = 'yes' == get_option( 'afadv_enable_decimal_quantity' ) ? array( 'step' => '0.01' ) : '';
		
		if (null == $section) {

			// Add Title to the Settings
			$settings[] = array(
				'name' => __( 'Configurations', 'addify-product-qty' ),
				'type' => 'title',
				'id'   => 'afadvqty_configuration_section',
			);

			$settings[] = array(
				'name'     => __( 'Show/Hide Quantity Box', 'addify-product-qty' ),
				'id'       => 'afadv_config_show_hide_fld',
				'type'     => 'checkbox',
				'desc_tip' => __( 'Show / Hide Quantity box on listing pages (OPTIONAL)', 'addify-product-qty' ),
			);

			$settings[] = array(
				'name'     => __( 'Enable/Disable Decimal Quantity', 'addify-product-qty' ),
				'id'       => 'afadv_enable_decimal_quantity',
				'type'     => 'checkbox',
				'desc_tip' => __( 'Enable decimal quantities for WooCommerce. Note: By default WooCommerce uses integer quantities for products.', 'addify-product-qty' ),
			);

			$settings[] = array(
				'type' => 'sectionend',
				'id'   => 'afadvqty_configuration_section',
			);

			
		} elseif ('cart-quantities' == $section) {

			global $wp_roles;
			$roles             = $wp_roles->get_names();
			$user_role_options = array();

			foreach ($roles as $key => $value) { 

				$user_role_options[ $key ] = translate_user_role( $value, 'default' );
			}

			$user_role_options['guest'] = esc_html__('Guest', 'addify-product-qty');

			$spec_pro = get_option('afadv_exl_pro_cart_fld');

			$spec_pro = is_array($spec_pro) ? $spec_pro : array();

			$selected_pro = array();
			if (!empty($spec_pro)) {
				foreach ($spec_pro as $key) {
					$product                      = wc_get_product(intval($key));
					$selected_pro[ intval($key) ] = $product->get_title(); 
				}
			}

			$spec_cat = get_option('afadv_exl_pro_cart_fld');

			$spec_cat = is_array($spec_cat) ? $spec_cat : array();

			$selected_cat = array();

			$cat_list = get_terms('product_cat');
			
			if (!empty($cat_list)) {
				foreach ($cat_list as $term) {
					$selected_cat[ $term->term_id ] = $term->name;
				}
			}


			// Add Title to the Settings
			$settings[] = array(
				'name' => __( 'Cart Quantities Configurations', 'addify-product-qty' ),
				'type' => 'title',
				'id'   => 'afadvqty_cart_qty_section',
			);

			$settings[] = array(
				'name'              => __( 'Minimum Quantity', 'addify-product-qty' ),
				'id'                => 'afadv_cart_config_min_qnt_fld',
				'type'              => 'number',
				'custom_attributes' => $custom_attributes,
			);

			$settings[] = array(
				'name'              => __( 'Maximum Quantity', 'addify-product-qty' ),
				'id'                => 'afadv_cart_config_max_qnt_fld',
				'type'              => 'number',
				'custom_attributes' => $custom_attributes,
			);

			$settings[] = array(
				'name'              => __( 'Multiple of No.', 'addify-product-qty' ),
				'id'                => 'afadv_cart_config_mod_no_fld',
				'type'              => 'number',
				'custom_attributes' => $custom_attributes, 
			);

			$settings[] = array(
				'name'              => __( 'Minimum Amount', 'addify-product-qty' ),
				'id'                => 'afadv_cart_config_min_cartamnt_fld',
				'type'              => 'number',
				'custom_attributes' => array( 'step' => '0.01' ),
			);

			$settings[] = array(
				'name'              => __( 'Maximum Amount', 'addify-product-qty' ),
				'id'                => 'afadv_cart_config_max_cartamnt_fld',
				'type'              => 'number',
				'custom_attributes' => array( 'step' => '0.01' ),    
			);

			$settings[] = array(
				'type' => 'sectionend',
				'id'   => 'afadvqty_cart_qty_section',
			);

			// Add Title to the Settings
			$settings[] = array(
				'name' => __( 'Exclude products and categories', 'addify-product-qty' ),
				'type' => 'title',
				'id'   => 'afadvqty_cart_exclude_pros',
				'desc' => __( 'These settings will be applied to the selected roles in the CART Configurations section.', 'addify-product-qty' ),
			);

			$settings[] = array(
				'title'    => __( 'Select Products', 'addify-product-qty' ),
				'class'    => 'product-select-multiple',
				'multiple' => true,
				'css'      => 'min-width: 350px;',
				'id'       => 'afadv_exl_pro_cart_fld',
				'type'     => 'multiselect',
				'default'  => '',
				'options'  => $selected_pro,
				'desc_tip' => __('Select Products to exclude from the CART limits.', 'addify-product-qty'),
			
			);
			$settings[] = array(
				'title'    => __( 'Select Categories', 'addify-product-qty' ),
				'class'    => 'category-select-multiple',
				'multiple' => true,
				'css'      => 'min-width: 350px;',
				'id'       => 'afadv_exl_cat_cart_fld',
				'type'     => 'multiselect',
				'default'  => '',
				'options'  => $selected_cat,
				'desc_tip' => __('Select Categories to exclude from the CART limits.', 'addify-product-qty'),
			
			);

			$settings[] = array(
				'type' => 'sectionend',
				'id'   => 'afadvqty_cart_exclude_pros',
			);

			$settings[] = array(
				'name' => __( 'Cart Notices', 'addify-product-qty' ),
				'type' => 'title',
				'id'   => 'afadvqty_cart_notice_section',
			);

			$settings[] = array(
				'name'     => __( 'Minimum Quantity Message', 'addify-product-qty' ),
				'id'       => 'afadv_cart_notices_min_qnt_msg_fld',
				'type'     => 'textarea',
				'css'      => 'min-width:300px; min-height:100px;',
				'desc_tip' => __('[min-cart-qty], [add-cart-qty] & [excluded_products] Variables to use in Message.', 'addify-product-qty'),
				
			
			);

			$settings[] = array(
				'name'     => __( 'Maximum Quantity Message', 'addify-product-qty' ),
				'id'       => 'afadv_cart_notices_max_qnt_msg_fld',
				'type'     => 'textarea',
				'css'      => 'min-width:300px; min-height:100px;',
				'desc_tip' => __('[excluded_products], [max-cart-qty] & [rem-cart-qty] Variables to use in Message.', 'addify-product-qty'),
				
			
			);

			$settings[] = array(
				'name'     => __( 'Multiple of No. Message', 'addify-product-qty' ),
				'id'       => 'afadv_cart_notices_mod_no_msg_fld',
				'type'     => 'textarea',
				'css'      => 'min-width:300px; min-height:100px;',
				'desc_tip' => __('[excluded_products], [cart-mul-num] & [cart-qty] Variables to use in Message.', 'addify-product-qty'),
				
			
			);

			$settings[] = array(
				'name'     => __( 'Minimum Amount Message', 'addify-product-qty' ),
				'id'       => 'afadv_cart_notices_min_cartamnt_msg_fld',
				'type'     => 'textarea',
				'css'      => 'min-width:300px; min-height:100px;',
				'desc_tip' => __('[excluded_products], [min-cart-amnt] & [add-cart-amnt] Variables to use in Message', 'addify-product-qty'),
				
			
			);

			$settings[] = array(
				'name'     => __( 'Maximum Amount Message', 'addify-product-qty' ),
				'id'       => 'afadv_cart_notices_max_cartamnt_msg_fld',
				'type'     => 'textarea',
				'css'      => 'min-width:300px; min-height:100px;',
				'desc_tip' => __('[excluded_products], [max-cart-amnt] & [rem-cart-amnt] Variables to use in Message', 'addify-product-qty'),
				
			
			);


			$settings[] = array(
				'name'     => __( 'Select User Roles', 'addify-product-qty' ),
				'class'    => 'wc-enhanced-select',
				'id'       => 'afadv_cart_config_rest_role_fld',
				'type'     => 'multiselect',
				'options'  => $user_role_options,
				'desc_tip' => __('If no user role is selected then it will be applied on all user roles.', 'addify-product-qty'),
			
			);

			$settings[] = array(
				'type' => 'sectionend',
				'id'   => 'afadvqty_cart_notice_section',
			);

		}

		return apply_filters( 'wc_settings_tab_afadvqty_settings', $settings, $section );
	}

	/**
	 * Output the settings
	 */
	public function output() {
		global $current_section;

		$settings = $this->get_settings( $current_section );
		if (!empty($settings )) {
			WC_Admin_Settings::output_fields( $settings );
		}
	}


	/**
	 * Save settings
	 */
	public function save() {
		global $current_section;
		$settings = $this->get_settings( $current_section );
		WC_Admin_Settings::save_fields( $settings );
	}
}

return new WC_Settings_Addify_Advance_Product_Quantity();
