/** * Get real values from data availble in cart * * @since 0.0.0 * @access public * @static * * @param string $param Key * * @return integer|boolean */ public static function get_real_value($param) { switch ($param) { case 'num_products': return WFG_Product_Helper::get_main_product_quantity_count(); case 'total_price': return WC()->cart->cart_contents_total; } }
/** * Display gifts. * * @since 1.1.0 * @access public * * @return void */ protected function _show_gifts() { if (!$this->_wfg_enabled) { return; } if (empty($this->_wfg_products)) { return; } $wfg_free_products = array(); foreach ($this->_wfg_products as $product) { $wfg_free_products[] = WFG_Product_Helper::get_product_details($product); } $localize = array('gifts_allowed' => false !== $this->_wfg_gifts_allowed ? $this->_wfg_gifts_allowed : 1); echo '<script>'; echo '/* ' . '<![CDATA[ */'; echo 'var WFG_SPECIFIC =' . json_encode($localize); echo '/* ]]> */'; echo '</script>'; include PLUGIN_DIR . 'templates/default/template-default.php'; }
/** * 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 }
public function ajax_product_list_callback() { $q = isset($_GET['q']) ? $_GET['q'] : ''; if (!$q) { return 0; } $products = WFG_Product_Helper::get_products(array('s' => $q, 'posts_per_page' => 15)); $list = array(); if (!empty($products) && !empty($products->posts)) { foreach ($products->posts as $product) { $list[] = array('id' => $product->ID, 'text' => $product->post_title); } } echo json_encode(array('options' => $list)); wp_die(); }
<p> <label><?php echo WFG_Common_Helper::translate('Select Gift Products'); ?> </label> </p> <div class="_wfg-repeat"> <select class='wfg-ajax-select' data-placeholder='<?php echo WFG_Common_Helper::translate('Choose gifts'); ?> ' name='_wfg_criteria[criteria-1][items][]' multiple> <?php if (!empty($condition['items'])) { $products = WFG_Product_Helper::get_products(array('post__in' => $condition['items']), -1); ?> <p class="wfg-inputs wfg-criteria-options-wrap"> <?php if ($products->have_posts()) { while ($products->have_posts()) { $products->the_post(); $selected = ''; if (in_array(get_the_ID(), $condition['items'])) { $selected = 'selected'; } echo "<option value='" . get_the_ID() . "' {$selected} >" . get_the_title() . '</option>'; } } ?> </p>
/** * Display gift popup in frontend. * * @since 0.0.0 * @access public * * @return void */ public function display_gifts() { if (!is_cart()) { return; } if ($this->__gift_item_in_cart()) { return; } self::__get_actual_settings(); //check gift criteria if ('single_gift' !== $this->_wfg_type) { $gift_criteria = WFG_Settings_Helper::get('global_gift_criteria'); if (!empty($gift_criteria)) { $criteria = WFG_Criteria_Helper::parse_criteria($gift_criteria); if (!$criteria) { return; } } } //enqueue required styles for this page wp_enqueue_style('wfg-core-styles', plugins_url('/css/wfg-styles.css', dirname(__FILE__))); wp_enqueue_style('wfg-template-styles', plugins_url('/templates/default/wfg-default.css', dirname(__FILE__))); $items = WFG_Product_Helper::get_cart_products(); if ($items['count'] >= $this->_minimum_qty) { if ($this->_wfg_enabled) { if (!empty($this->_wfg_products)) { $wfg_free_products = array(); foreach ($this->_wfg_products as $product) { $wfg_free_products[] = WFG_Product_Helper::get_product_details($product); } $localize = array('gifts_allowed' => $this->_wfg_gifts_allowed !== false ? $this->_wfg_gifts_allowed : 1); echo "<script>"; echo "/* " . "<![CDATA[ */"; echo 'var WFG_SPECIFIC =' . json_encode($localize); echo "/* ]]> */"; echo "</script>"; include PLUGIN_DIR . 'templates/default/template-default.php'; } } } }
/** * Select box to get products using ajax * * @since 1.1.0 * @access private * * @param array $wfg_products Products selected previously * @param int $post_id Post id * * @return string */ private function get_ajax_product_selection_design($wfg_products, $post_id) { $html = "<select class='wfg-ajax-select' id='wfg-select-" . uniqid() . "' name='_wfg_single_gift_products[]' multiple='multiple'>"; if (!empty($wfg_products)) { $product_list = WFG_Product_Helper::get_products(array('post__in' => $wfg_products, 'post__not_in' => array($post_id)), -1); $products = $product_list->get_posts(); if (!empty($products)) { foreach ($products as $product) { $product_id = $product->ID; $selected = in_array($product_id, $wfg_products); $html .= "<option value='" . $product_id . "' " . ($selected ? 'selected' : '') . ">" . $product->post_title . "</option>"; } } } $html .= '</select>'; return $html; }
<div class="header clearfix"> <div class="left"> <?php echo '<img src="' . plugins_url('img/wfg-logo.png', dirname(__FILE__)) . '" > '; ?> </div> <div class="left"> <h1><?php echo WFG_Common_Helper::translate('WooCommerce Multiple Free Gift'); ?> </h1> </div> <div class="right"></div> </div> <?php $products = WFG_Product_Helper::get_products(); ?> <div id="wfg_free_gift_global_settings"> <form name="wfg_main_menu_form" method="post" action=""> <h2></h2> <?php wp_nonce_field('wfg_global_settings', '_wfg_global_nonce'); ?> <?php if ($products->have_posts()) { ?> <div class="options_group"> <p class="form-field wfg_form_field switcher "> <?php $checked = ''; if (WFG_Settings_Helper::get('global_enabled', true, 'global_options')) {
public function ajax_product_list_callback() { $q = isset($_POST['data']['q']) ? $_POST['data']['q'] : ''; if (!$q) { return null; } $products = WFG_Product_Helper::get_products(array('s' => $q)); $list = array(); if (!empty($products) && !empty($products->posts)) { foreach ($products->posts as $product) { $list[] = array('id' => $product->ID, 'text' => $product->post_title); } } echo json_encode(array('q' => $q, 'results' => $list)); wp_die(); }