>
>
>
>

>
$category) { $category->term_id; $title = ( mb_strlen( $category->name ) > 50 ) ? mb_substr( $category->name, 0, 49 ) . '...' : $category->name; $return[] = array( $category->term_id, $title ); } } echo json_encode( $return ); die; } function recursive_sanitize_text_field($array) { if(!empty($array)) { foreach ( $array as $key => $value ) { if ( is_array( $value ) ) { $value = $this->recursive_sanitize_text_field($value); }else{ $value = sanitize_text_field( $value ); } } } return $array; } function OCGW_save_options(){ if( current_user_can('administrator') ) { if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'gw_save_option') { if(!isset( $_POST['OCGW_meta_save_nounce'] ) || !wp_verify_nonce( $_POST['OCGW_meta_save_nounce'], 'OCGW_meta_save' ) ) { print 'Sorry, your nonce did not verify.'; exit; } else { $isecheckbox = array( 'gw_gift_wrapper_enable', 'gw_gift_wrapper_msg_enable', 'gw_ckout_enable', 'gw_gift_wrapper_single_product_page', 'gw_gift_wrapper_remove_gift_items', 'gw_allow_only_logged_in', 'gw_mtvtion_msg_enable', 'showslider_autoplay_or_not', 'gw_gift_wrapper_open_single_product_page', ); foreach ($isecheckbox as $key_isecheckbox => $value_isecheckbox) { if(!isset($_REQUEST['ocgw_comman'][$value_isecheckbox])){ $_REQUEST['ocgw_comman'][$value_isecheckbox] ='no'; } } /*---custom rules---*/ if(!empty($_REQUEST['gw_select2'])) { $gw_combo = $this->recursive_sanitize_text_field( $_REQUEST['gw_select2'] ); update_option('gw_combo', $gw_combo, 'yes'); } else { update_option('gw_combo', '', 'yes'); } if(!empty($_REQUEST['gw_gift_wrapper_select2'])) { $gw_gift_wrapper_combo = $this->recursive_sanitize_text_field( $_REQUEST['gw_gift_wrapper_select2'] ); update_option('gw_gift_wrapper_combo', $gw_gift_wrapper_combo, 'yes'); } else { update_option('gw_gift_wrapper_combo', '', 'yes'); } foreach ($_REQUEST['ocgw_comman'] as $key_ocgw_comman => $value_ocgw_comman) { update_option($key_ocgw_comman, sanitize_text_field($value_ocgw_comman), 'yes'); } } wp_redirect( admin_url( '/admin.php?page=free_gift_wrapper' ) ); exit; } } } function OCGW_cats_ajax() { $return = array(); $product_categories = get_terms( 'product_cat', $cat_args ); if( !empty($product_categories) ){ foreach ($product_categories as $key => $category) { $category->term_id; $title = ( mb_strlen( $category->name ) > 50 ) ? mb_substr( $category->name, 0, 49 ) . '...' : $category->name; $return[] = array( $category->term_id, $title ); } } echo json_encode( $return ); die; } function OCWG_product_ajax(){ $date = ($_REQUEST); } function OCGW_product_ajax() { $return = array(); $post_types = array( 'product','product_variation'); $search_results = new WP_Query( array( 's'=> sanitize_text_field($_GET['q']), 'post_status' => 'publish', 'post_type' => $post_types, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ) ) ) ); if( $search_results->have_posts() ) { while( $search_results->have_posts() ) { $search_results->the_post(); $productc = wc_get_product( $search_results->post->ID ); if( $productc && $productc->is_in_stock() && $productc->is_purchasable() ) { $title = $search_results->post->post_title; $price = $productc->get_price_html(); $return[] = array( $search_results->post->ID, $title, $price); } } } echo json_encode( $return ); die; } function init() { add_action('admin_menu', array($this, 'OCGW_create_menu')); add_action( 'wp_ajax_nopriv_gw_product_ajax',array($this, 'OCGW_product_ajax') ); add_action( 'wp_ajax_gw_product_ajax', array($this, 'OCGW_product_ajax') ); add_action( 'wp_ajax_nopriv_gw_cat_ajax',array($this, 'OCGW_cat_ajax') ); add_action( 'wp_ajax_gw_cat_ajax', array($this, 'OCGW_cat_ajax') ); add_action( 'wp_ajax_nopriv_gw_cats_ajax',array($this, 'OCGW_cats_ajax') ); add_action( 'wp_ajax_gw_cats_ajax', array($this, 'OCGW_cats_ajax') ); add_action( 'init', array($this, 'OCGW_save_options')); } public static function instance() { if (!isset(self::$instance)) { self::$instance = new self(); self::$instance->init(); } return self::$instance; } } OCGW_menu::instance(); }