<th scope="row">
						<label for="invalid_condition"><?php 
echo WFG_Common_Helper::translate('Invalid Gift Condition Text');
?>
</label>
					</th>
					<td>
						<?php 
$invalidText = WFG_Settings_Helper::get('invalid_condition_text', false, 'global_options');
if ($invalidText === false) {
    $invalidText = WFG_Common_Helper::translate('Gift items removed as gift criteria isn\'t fulfilled');
}
?>
						<input type="text" name="_wfg_invalid_condition_text" id="invalid_condition" class="regular-text"
							value="<?php 
echo $invalidText;
?>
" />
					</td>
				</tr>
			</tbody>
		</table>
		<p class="submit">
			<input type="hidden" name="_wfg_general_settings_submitted" value="Y" class="button button-primary" />
			<input type="submit" value="<?php 
echo WFG_Common_Helper::translate('Save Changes');
?>
" class="button button-primary" />
		</p>
	</form>
</div>
    /**
     * Error notice: WooCommerce Plugin is required for this plugin to work
     *
     * @access public
     * @since  0.0.0
     *
     * @return void
     */
    public function wfg_plugin_required_notice()
    {
        WFG_Common_Helper::error_notice(WFG_Common_Helper::translate('WooCommerce Free Gift plugin requires
				<a href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>
				plugin to work. Please make sure that WooCommerce is installed and activated.'));
    }
 /**
  * Add free gift item to cart.
  *
  * @since  0.0.0
  * @access public
  * @static
  *
  * @param integer $parent_product_id Main product id
  * @param integer $product_id Product variation id
  *
  * @return  void
  */
 public static function add_free_product_to_cart($parent_product_id, $product_id)
 {
     $found = false;
     //check if product is already in cart
     if (count(WC()->cart->get_cart()) > 0) {
         foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
             $_product = $values['data'];
             if ($_product->id == $product_id) {
                 $found = true;
             }
         }
         // if product not found, add it
         if (!$found) {
             WC()->cart->add_to_cart($product_id, 1, $parent_product_id, array(WFG_Common_Helper::translate('Type') => WFG_Common_Helper::translate('Free Item')));
         }
     }
 }
" 
										class="wfg-input-small wfg-adjust-position wfg-condition-value" required />
								</div>
						</div>
				</div>
			</div>

			<div class="options_group">
				<p>
					<input type="hidden" name="_wfg_criteria_hidden" value="Y" />
					<button class="button button-primary" type="submit"><?php 
echo WFG_Common_Helper::translate('Save');
?>
</button>
				</p>
			</div>			
		</form>
	</div>
</div>
<?php 
echo WFG_Common_Helper::translate('You can add multiple gift criteria in premium version.');
?>
&nbsp;
		<a href="<?php 
echo PRO_URL;
?>
" title="Buy WooCommerce Free Gift PRO"><?php 
echo WFG_Common_Helper::translate('Learn more...');
?>
</a>
 public function wfg_general_settings()
 {
     if (isset($_POST['_wfg_general_settings_submitted']) && $_POST['_wfg_general_settings_submitted'] == 'Y' && wp_verify_nonce($_POST['_wfg_general_nonce'], 'wfg_general_settings')) {
         $popup_overlay = isset($_POST['_wfg_popup_overlay']) ? 1 : 0;
         $popup_heading = isset($_POST['_wfg_popup_heading']) ? $_POST['_wfg_popup_heading'] : WFG_Common_Helper::translate('Choose your free gift');
         $invalid_text = isset($_POST['_wfg_invalid_condition_text']) ? $_POST['_wfg_invalid_condition_text'] : WFG_Common_Helper::translate('Gift items removed as gift criteria isn\'t fulfilled');
         $add_gift_text = isset($_POST['_wfg_popup_add_gift_text']) ? $_POST['_wfg_popup_add_gift_text'] : WFG_Common_Helper::translate('Add Gifts');
         $cancel_text = isset($_POST['_wfg_popup_cancel_text']) ? $_POST['_wfg_popup_cancel_text'] : WFG_Common_Helper::translate('No Thanks');
         $overlay = update_option('_wfg_popup_overlay', $popup_overlay);
         $heading = update_option('_wfg_popup_heading', $popup_heading);
         $invalid = update_option('_wfg_invalid_condition_text', $invalid_text);
         $add_gift = update_option('_wfg_popup_add_gift_text', $add_gift_text);
         $cancel_text = update_option('_wfg_popup_cancel_text', $cancel_text);
         if ($overlay || $heading || $invalid || $add_gift || $cancel_text) {
             WFG_Common_Helper::success_notice(WFG_Common_Helper::translate('Settings saved successfully'));
             //update settings
             WFG_Settings_Helper::force_init();
         } else {
             WFG_Common_Helper::error_notice(WFG_Common_Helper::translate('No changes to save.'));
         }
     }
     include "pages/general_settings.php";
 }
 /**
  * Set notice text.
  *
  * @since  1.1.0
  * @access private
  *
  * @return void
  */
 private function __set_notice_text()
 {
     $noticeText = WFG_Settings_Helper::get('invalid_condition_text', false, 'global_options');
     if (false === $noticeText) {
         $noticeText = WFG_Common_Helper::translate('Gift items removed as gift criteria isn\'t fulfilled');
     }
     WFG_Common_Helper::fixed_notice($noticeText);
 }
    /**
     * Free gift tab contents
     *
     * @since  0.0.0
     * @access public
     *
     * @return void
     */
    public function wfg_tab_contents()
    {
        $post_id = get_the_ID();
        $wfg_enabled = get_post_meta($post_id, '_wfg_single_gift_enabled', true);
        $wfg_products = get_post_meta($post_id, '_wfg_single_gift_products', true);
        $wfg_gifts_allowed = get_post_meta($post_id, '_wfg_single_gift_allowed', true);
        ?>
		<div id="wfg_free_gift_tab" class="panel woocommerce_options_panel">
			<div class="options_group">
				<p class="form-field wfg_form_field">
					<input type="checkbox" class="checkbox" style="" name="wfg_single_gift_enabled" id="wfg_single_gift_enabled" <?php 
        echo $wfg_enabled ? 'checked' : '';
        ?>
>
					<label for="wfg_single_gift_enabled" class="description">
						<?php 
        echo WFG_Common_Helper::translate('Enable free gift for this product.');
        ?>
					</label>
					<img class="help_tip" src="<?php 
        echo WP_PLUGIN_URL;
        ?>
/woocommerce/assets/images/help.png" height="16" width="16" data-tip="
					<?php 
        echo WFG_Common_Helper::translate('Enabling single gift settings will overwrite global settings.');
        ?>
" />
				</p>
			</div>
			<p class="wfg-adjust-form-field-gap">
				<label><?php 
        echo WFG_Common_Helper::translate('Select Gift Products');
        ?>
</label>
				<img class="help_tip" src="<?php 
        echo WP_PLUGIN_URL;
        ?>
/woocommerce/assets/images/help.png" height="16" width="16" data-tip="
					<?php 
        echo WFG_Common_Helper::translate('Select single/multiple gift items you want to giveaway for free.');
        echo '<br/><br/>';
        echo WFG_Common_Helper::translate('Note that duplicate items are saved only once.');
        ?>
" />
			</p>
			<div class="_wfg-repeat">
				<select class='chosen' data-placeholder='<?php 
        echo WFG_Common_Helper::translate('Choose gifts');
        ?>
' name='_wfg_single_gift_products[]' multiple>
				<?php 
        if (!empty($wfg_products)) {
            $products = WFG_Product_Helper::get_products(array('post__in' => $wfg_products, 'post__not_in' => array($post_id)), -1);
            foreach ($wfg_products as $key => $product) {
                ?>
							<p class="wfg-inputs">
								<?php 
                if ($products->have_posts()) {
                    while ($products->have_posts()) {
                        $products->the_post();
                        $product_id = get_the_ID();
                        echo "<option value='" . $product_id . "' " . ($product_id == $product ? 'selected' : '') . ">" . get_the_title() . "</option>";
                    }
                }
                ?>
							</p>
				<?php 
            }
        }
        ?>
				</select>
			</div>

			<p class="form-field wfg_form_field">
				<label for="wfg_gifts_allowed" class="description">
					<?php 
        echo WFG_Common_Helper::translate('Number of gifts allowed');
        ?>
				</label>
				<input type="text" class="input-text input-small" name="wfg_single_gift_allowed" id="wfg_gifts_allowed" value="<?php 
        echo !empty($wfg_gifts_allowed) && $wfg_gifts_allowed >= 0 ? $wfg_gifts_allowed : 1;
        ?>
" />
				<img class="help_tip" src="<?php 
        echo WP_PLUGIN_URL;
        ?>
/woocommerce/assets/images/help.png" height="16" width="16" data-tip="
					<?php 
        echo WFG_Common_Helper::translate('Number of items user are allowed to select as a gift.
							Value zero or less will allow unlimited selection.');
        ?>
" />
			</p>
		</div>
<?php 
    }
                </div>

                <input type="hidden" name="_wfg_global_hidden" value="Y"/>
                <button class="button-primary"
                        type="submit"><?php 
    echo WFG_Common_Helper::translate('Save');
    ?>
</button>
            <?php 
} else {
    ?>
                <div class="options_group">
                    <p class="wfg-info-wrapper form-field wfg_form_field switcher">
                        <?php 
    echo get_permalink(woocommerce_get_page_id('product'));
    $message = WFG_Common_Helper::translate('Please add some');
    $message .= ' ';
    $message .= '<a href="edit.php?post_type=product">' . WFG_Common_Helper::translate('products') . '</a>';
    $message .= ' ';
    $message .= WFG_Common_Helper::translate('first.');
    echo $message;
    ?>
                    </p>
                </div>
            <?php 
}
?>
        </form>
    </div>
</div>
 /**
  * Remove gifts if the criteria is invalid.
  *
  * @since  0.0.0
  * @access public
  *
  * @return void
  */
 public function validate_gifts()
 {
     if (!is_cart()) {
         return;
     }
     if (!$this->__gift_item_in_cart()) {
         return;
     }
     self::__get_actual_settings();
     if ('single_gift' === $this->_wfg_type) {
         $total_items_in_cart = WFG_Product_Helper::get_main_product_count();
         if (1 === $total_items_in_cart) {
             foreach (WC()->cart->cart_contents as $key => $content) {
                 $is_gift_product = !empty($content['variation_id']) && (bool) get_post_meta($content['variation_id'], '_wfg_gift_product');
                 if ($is_gift_product && !in_array($content['product_id'], $this->_wfg_products)) {
                     WC()->cart->remove_cart_item($key);
                 }
             }
         }
     }
     $cart_items = WFG_Product_Helper::get_gift_products_in_cart();
     if (!$this->_wfg_criteria || !WFG_Product_Helper::crosscheck_gift_items($cart_items, $this->_wfg_products)) {
         //remove gift products
         $removed = false;
         foreach (WC()->cart->cart_contents as $key => $content) {
             $is_gift_product = !empty($content['variation_id']) && (bool) get_post_meta($content['variation_id'], '_wfg_gift_product');
             if ($is_gift_product) {
                 WC()->cart->remove_cart_item($key);
                 $removed = true;
             }
         }
         if ($removed) {
             $noticeText = WFG_Settings_Helper::get('invalid_condition_text', false, 'global_options');
             if ($noticeText === false) {
                 $noticeText = WFG_Common_Helper::translate('Gift items removed as gift criteria isn\'t fulfilled');
             }
             WFG_Common_Helper::fixed_notice($noticeText);
         }
     }
 }
    /**
     * Free gift tab contents
     *
     * @since  0.0.0
     * @access public
     *
     * @return void
     */
    public function wfg_tab_contents()
    {
        $post_id = get_the_ID();
        $wfg_enabled = get_post_meta($post_id, '_wfg_single_gift_enabled', true);
        $wfg_products = get_post_meta($post_id, '_wfg_single_gift_products', true);
        $wfg_gifts_allowed = get_post_meta($post_id, '_wfg_single_gift_allowed', true);
        ?>
        <div id="wfg_free_gift_tab" class="panel woocommerce_options_panel">
            <div class="options_group">
                <p class="form-field wfg_form_field">
                    <input type="checkbox" class="checkbox" style="" name="wfg_single_gift_enabled"
                           id="wfg_single_gift_enabled" <?php 
        echo $wfg_enabled ? 'checked' : '';
        ?>
>
                    <label for="wfg_single_gift_enabled" class="description">
                        <?php 
        echo WFG_Common_Helper::translate('Enable free gift for this product.');
        ?>
                    </label>
                    <img class="help_tip" src="<?php 
        echo WP_PLUGIN_URL;
        ?>
/woocommerce/assets/images/help.png"
                         height="16" width="16" data-tip="
					<?php 
        echo WFG_Common_Helper::translate('Enabling single gift settings will overwrite global settings.');
        ?>
"/>
                </p>
            </div>
            <p class="wfg-adjust-form-field-gap">
                <label><?php 
        echo WFG_Common_Helper::translate('Select Gift Products');
        ?>
</label>
                <img class="help_tip" src="<?php 
        echo WP_PLUGIN_URL;
        ?>
/woocommerce/assets/images/help.png" height="16"
                     width="16" data-tip="
					<?php 
        echo WFG_Common_Helper::translate('Select single/multiple gift items you want to giveaway for free.');
        echo '<br/><br/>';
        echo WFG_Common_Helper::translate('Note that duplicate items are saved only once.');
        ?>
"/>
            </p>
            <div class="_wfg-repeat">
                <?php 
        echo self::get_ajax_product_selection_design($wfg_products, $post_id);
        ?>
            </div>

            <p class="form-field wfg_form_field">
                <label for="wfg_gifts_allowed" class="description">
                    <?php 
        echo WFG_Common_Helper::translate('Number of gifts allowed');
        ?>
                </label>
                <input type="text" class="input-text input-small" name="wfg_single_gift_allowed" id="wfg_gifts_allowed"
                       value="<?php 
        echo !empty($wfg_gifts_allowed) && $wfg_gifts_allowed >= 0 ? $wfg_gifts_allowed : 1;
        ?>
"/>
                <img class="help_tip" src="<?php 
        echo WP_PLUGIN_URL;
        ?>
/woocommerce/assets/images/help.png" height="16"
                     width="16" data-tip="
					<?php 
        echo WFG_Common_Helper::translate('Number of items user are allowed to select as a gift.
							Value zero or less will allow unlimited selection.');
        ?>
"/>
            </p>
        </div>
        <?php 
    }
    }
    ?>
				<div class="wfg-actions">
					<button class="wfg-button wfg-add-gifts">
						<?php 
    $add_gift_text = WFG_Settings_Helper::get('popup_add_gift_text', false, 'global_options');
    if ($add_gift_text !== false) {
        echo $add_gift_text;
    } else {
        echo WFG_Common_Helper::translate('Add Gifts');
    }
    ?>
					</button>
					<button class="wfg-button wfg-no-thanks" type="button">
						<?php 
    $cancel_text = WFG_Settings_Helper::get('popup_cancel_text', false, 'global_options');
    if ($cancel_text !== false) {
        echo $cancel_text;
    } else {
        echo WFG_Common_Helper::translate('No Thanks');
    }
    ?>
					</button>
				</div>
			<?php 
}
?>
		</form>
	</div>
</div>