<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Elex_Fpf_Ajax_Call {

private $setting_tab_fields;
	public function __construct() {
		add_action( 'wp_ajax_elex_fpf_show_mapping_fields', array( $this, 'elex_fpf_mapping_settings_field' ) );
		add_action( 'wp_ajax_elex_fpf_generate_feed', array( $this, 'elex_fpf_generate_feed' ) );
		add_action( 'wp_ajax_elex_fpf_manage_feed_edit_file', array( $this, 'elex_fpf_manage_feed_edit_file' ) );
		add_action( 'wp_ajax_elex_fpf_get_exclude_prod_option', array( $this, 'elex_fpf_get_exclude_prod_option' ) );
		add_action( 'wp_ajax_elex_fpf_pause_schedule', array( $this, 'elex_fpf_pause_schedule' ) );
		add_action( 'wp_ajax_elex_fpf_name_title_validate', array( $this, 'elex_fpf_validate_title' ) );
		add_action( 'wp_ajax_check_if_the_feed_exists', array( $this, 'check_if_the_feed_exists' ) );

		$this->setting_tab_fields = get_option( 'elex_fpf_settings_tab_fields_data' );

	}

	public function check_if_the_feed_exists() {
		check_ajax_referer( 'ajax-elex-fpf-nonce', '_ajax_elex_fpf_nonce' );

		if ( isset( $_POST['is_edit_project'] ) ) {
			if ( 'false' === sanitize_text_field( $_POST['is_edit_project'] ) ) {
				$is_edit_project = false;
			} elseif ( 'true' === sanitize_text_field( $_POST['is_edit_project'] ) ) {
				$is_edit_project = true;
			} else {
				$is_edit_project = true;
			}       
		}
		

		$project_title = isset( $_POST['project_title'] ) ? sanitize_text_field( $_POST['project_title'] ) : '';
		$this->check_for_duplicate_feed( $project_title, $is_edit_project );

	}

	public function check_for_duplicate_feed( $project_title, $is_edit_project ) {
		if ( 'false' === $is_edit_project ) {
			$is_edit_project = false;
		}

		if ( false !== $is_edit_project ) {
			return;
		}
		
		global $wpdb;


		$result = $wpdb->get_results( $wpdb->prepare( "SELECT feed_meta_content from {$wpdb->prefix}fpf_feeds WHERE feed_meta_content LIKE %s  AND  feed_meta_key = 'manage_feed_data' ", '%' . $wpdb->esc_like( $project_title ) . '%' ) );
		if ( empty( $result ) ) {
			return;
		}  

		foreach ( $result as $row ) {
			$row = json_decode( $row->feed_meta_content, true );

			if ( $project_title === $row['name'] ) {
				wp_send_json( 'same_name' );
				die();
			}
		}
	}

	public function elex_fpf_validate_title() {

		if ( isset( $_POST['security'] ) && ! wp_verify_nonce( sanitize_text_field( $_POST['security'] ), 'title_nonce' ) ) {
			return;
		}

		if ( isset( $_POST['title_val'] ) && ! empty( $_POST['title_val'] ) ) {
			global $wpdb;
			$title_val = sanitize_text_field( $_POST['title_val'] );
			$title_val = str_replace( ' ', '_', $title_val );
			$check_val = '%"name":"' . $title_val . '"%';
			$result    = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->prefix}fpf_feeds where feed_meta_content LIKE %s ", $check_val ) );
			if ( ! empty( $result ) ) {
				die( 'same_name' );
			}
		}
	}

	public function elex_fpf_pause_schedule() {
		check_ajax_referer( 'ajax-elex-fpf-manage-feed-nonce', '_ajax_elex_fpf_manage_feed_nonce' );
		if ( isset( $_POST['file'] ) ) {
			$file             = sanitize_text_field( $_POST['file'] );
			$manage_feed_data = json_decode( elex_fpf_get_feed_data( $file, 'manage_feed_data' )[0]['feed_meta_content'], true );
			if ( isset( $_POST['feed_action'] ) && 'pause' === sanitize_text_field( $_POST['feed_action'] ) ) {
				$manage_feed_data['pause_schedule'] = 'paused';
			} else {
				$manage_feed_data['pause_schedule'] = 'ready';
			}
			elex_fpf_update_feed( $file, 'manage_feed_data', $manage_feed_data );
		}
		die();
	}

	public function elex_fpf_get_exclude_prod_option() {
		check_ajax_referer( 'ajax-elex-fpf-manage-feed-nonce', '_ajax_elex_fpf_manage_feed_nonce' );
		$options          = '';
		$exclude_prod_ids = isset( $_POST['exclude_prod_ids'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['exclude_prod_ids'] ) ) : array();
		foreach ( $exclude_prod_ids as $product_id ) {
			$product = wc_get_product( $product_id );
			if ( is_object( $product ) ) {
				$options .= '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
			}
		}
		wp_send_json( $options );
	}



	public function elex_fpf_generate_feed() {
		check_ajax_referer( 'ajax-elex-fpf-nonce', '_ajax_elex_fpf_nonce' );

		$selected_google_product_cats = ( isset( $_POST['selected_google_product_cats'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_google_product_cats'] ) ) : null;
		$selected_products            = array();
	
		if ( isset( $_POST['selected_products'] ) ) {
			$sanitized_selected_products = map_deep( wp_unslash( $_POST['selected_products'] ), 'sanitize_text_field' );
			foreach ( $sanitized_selected_products as $index => $prod_ids ) {
				$selected_products[ $index ] = is_array( $prod_ids ) ? array_map( 'sanitize_text_field', wp_unslash( $prod_ids ) ) : $prod_ids;
			}
		}
		$product_ids = array();
		if ( $selected_google_product_cats && $selected_products && ( count( $selected_products ) === count( $selected_google_product_cats ) && count( $selected_google_product_cats ) > 0 ) ) {
			foreach ( $selected_google_product_cats as $key => $item ) {
				if ( isset( $product_ids[ $selected_google_product_cats[ $key ] ] ) && is_array( $product_ids[ $selected_google_product_cats[ $key ] ] ) ) {
					$product_ids[ $selected_google_product_cats[ $key ] ] = array_unique( array_merge( $product_ids[ $selected_google_product_cats[ $key ] ], $selected_products[ $key ] ) );
				} else {
					$product_ids[ $selected_google_product_cats[ $key ] ] = $selected_products[ $key ];
				}
			}
		}
	
		$choosen_cat = '';
		$variation   = isset( $_POST['include_variation'] ) ? sanitize_text_field( $_POST['include_variation'] ) : false;

	

		if ( isset( $_POST['categories_choosen'] ) && ! empty( $_POST['categories_choosen'] ) && isset( $_POST['sel_google_cats'] ) ) {
			foreach ( $_POST as $categories_choosen_key => $categories_choosen_value ) {
				if ( 'categories_choosen' == $categories_choosen_key ) {
					
					foreach ( $categories_choosen_value as $key => $val ) {
						$cat_cond = '';
						if ( isset( $_POST['sel_google_cats'][ $key ] ) ) {
							   $cat_cond = ''; 
							   $cat_cond = "'" . sanitize_text_field( $val ) . "'";
						} else {
							$cat_cond = $cat_cond . ",'" . sanitize_text_field( $val ) . "'";
						}
						$ids_to_update = array();
						$cats_index    = sanitize_text_field( $_POST['sel_google_cats'][ $key ] );
					
						if ( isset( $product_ids[ $cats_index ] ) && is_array( $product_ids[ $cats_index ] ) ) {
							$ids_to_update = $this->elex_fpf_get_product_ids( $cat_cond, $variation );

						

							if ( $ids_to_update ) {
								$product_ids[ $cats_index ] = array_unique( array_merge( $product_ids[ $cats_index ], $ids_to_update ) );
							}
						} else {
							$product_ids[ $cats_index ] = $this->elex_fpf_get_product_ids( $cat_cond, $variation );
						}
						$choosen_cat = $cats_index;
					}               
				}
			}       
		} elseif ( isset( $_POST['categories_choosen'] ) && ! empty( $_POST['categories_choosen'] ) && ! isset( $_POST['sel_google_cats'] ) ) {
			$choosen_cat = 'no_category_selected';
			$cat_cond    = '';
			foreach ( $_POST as $categories_choosen_key => $categories_choosen_value ) {
				if ( 'categories_choosen' == $categories_choosen_key ) {
					foreach ( $categories_choosen_value as $key => $categories ) {
						if ( '' == $cat_cond ) {
							   $cat_cond = "'" . sanitize_text_field( $categories ) . "'";
						} else {
							$cat_cond = $cat_cond . ",'" . sanitize_text_field( $categories ) . "'";
						}
					}   
				}
			}
			
			$ids_to_update = $this->elex_fpf_get_product_ids( $cat_cond, $variation );
			
			if ( $ids_to_update ) {
				$product_ids[ $choosen_cat ] = array_unique( $ids_to_update );
			}
		}
		
		if ( empty( $product_ids ) ) {
			return;
		}
		
		$more_than_hundred = false;
		$last_chunk        = false;
		
		$num_of_product = isset( $product_ids[ $choosen_cat ] ) ? count( $product_ids[ $choosen_cat ] ) : count( $product_ids );

		if ( isset( $_POST['categories_choosen'] ) ) {
			if ( isset( $_POST['chunk'] ) ) {
				$chunk = sanitize_text_field( $_POST['chunk'] );
				if ( isset( $product_ids[ $choosen_cat ] ) && count( $product_ids[ $choosen_cat ] ) > ( 100 + ( $chunk * 100 ) ) ) {
					$product_ids[ $choosen_cat ] = array_slice( $product_ids[ $choosen_cat ], ( $chunk * 100 ), 100 );
					$more_than_hundred           = true;
				} elseif ( $chunk > 0 ) {
					$product_ids[ $choosen_cat ] = array_slice( $product_ids[ $choosen_cat ], ( $chunk * 100 ) );
					$more_than_hundred           = true;
					$last_chunk                  = true;
				}
			}
		}
	

		$project_title           = isset( $_POST['project_title'] ) ? trim( sanitize_text_field( $_POST['project_title'] ) ) : '';
		$project_desc            = isset( $_POST['description'] ) ? sanitize_text_field( $_POST['description'] ) : '';
		$project_title           = str_replace( ' ', '_', $project_title );
		$default_category_chosen = ( ! empty( $_POST['default_category_chosen'] ) ) ? sanitize_text_field( $_POST['default_category_chosen'] ) : '';
		$condition               = array();
		$prepend_attr            = array();
		$append_attr             = array();
		if ( isset( $_POST['conditions'] ) ) {
			
			foreach ( $_POST as $array_key => $array_value ) {
				if ( 'conditions' == $array_key ) {
					if ( is_array( $array_value ) ) {
						foreach ( $array_value as $key => $value ) {
							   $condition[ $key ] = $value;
							if ( is_array( $value ) ) {
								foreach ( $value as $key_2 => $value_2 ) {
											 $condition[ $key ][ $key_2 ] = $value_2;
									if ( is_array( $value_2 ) ) {
										foreach ( $value_2 as $key_3 => $value_3 ) {
														$condition[ $key ][ $key_2 ][ $key_3 ] = $value_3;
											if ( is_array( $value_3 ) ) {
												foreach ( $value_3 as $key_4 => $value_4 ) {
																   $condition[ $key ][ $key_2 ][ $key_3 ][ $key_4 ] = $value_4;
													if ( is_array( $value_4 ) ) {
														foreach ( $value_4 as $key_5 => $value_5 ) {
																			  $condition[ $key ][ $key_2 ][ $key_3 ][ $key_4 ][ $key_5 ] = sanitize_text_field( $value_5 );
														}
													} else {
														$condition[ $key ][ $key_2 ][ $key_3 ][ $key_4 ] = sanitize_text_field( $value_4 );

													}
												}
											} else {
												$condition[ $key ][ $key_2 ][ $key_3 ] = sanitize_text_field( $value_3 );
											}
										}
									}
								}
							}                       
						}
					}               
				}           
			}       
		}
 
		if ( isset( $_POST['prepend_attr'] ) ) {
			foreach ( $_POST as $array_key => $array_value ) {
				if ( 'prepend_attr' == $array_key ) {
					foreach ( $array_value as $key => $value ) {
						$prepend_attr[ $key ] = $value;
						foreach ( $value as $key_2 => $value_2 ) {
							   $prepend_attr[ $key ][ $key_2 ] = array_map( 'sanitize_text_field', wp_unslash( $value_2 ) );
						}
					}
				}
			}       
		}
	

		if ( isset( $_POST['append_attr'] ) ) {
			foreach ( $_POST as $array_key => $array_value ) {
				if ( 'append_attr' == $array_key ) {
					foreach ( $array_value as $key => $value ) {
						$append_attr[ $key ] = $value;
						foreach ( $value as $key_2 => $value_2 ) {
							   $append_attr[ $key ][ $key_2 ] = array_map( 'sanitize_text_field', wp_unslash( $value_2 ) );
						}
					}
				}
			}
		}

		$exclude_ids  = '';
		$prod_vendors = '';
		if ( isset( $_POST['exclude_ids'] ) ) {
			$exclude_ids = array_map( 'sanitize_text_field', wp_unslash( $_POST['exclude_ids'] ) );
		}
		if ( isset( $_POST['prod_vendor'] ) ) {
			$prod_vendors = array_map( 'sanitize_text_field', wp_unslash( $_POST['prod_vendor'] ) );
		}
		if ( isset( $_POST['currency_conversion_code'] ) && ! empty( $_POST['currency_conversion_code'] ) ) {
			$currency_code = sanitize_text_field( $_POST['currency_conversion_code'] );
		} else {
			$currency_code = get_woocommerce_currency();
		}

		$result  = elexFpfWPFluent()->table( 'fpf_feeds' )
		->select( 'feed_id' )
		->orderBy( 'feed_id', 'desc' )
		->limit( 1 )
		->get();
		$feed_id = isset( $result[0]->feed_id ) ? $result[0]->feed_id : null;
		$feed_id = array( $feed_id );

		if ( ! $feed_id ) {
			$feed_id = 1;
		} elseif ( ! sanitize_text_field( $_POST['chunk'] ) && isset( $_POST['is_edit_project'] ) && 'true' !== $_POST['is_edit_project'] ) {
			$feed_id = $feed_id[0] + 1;
		} elseif ( isset( $_POST['is_edit_project'] ) && 'true' === $_POST['is_edit_project'] ) {
			$feed_id = isset( $_POST['file_to_edit'] ) ? sanitize_text_field( $_POST['file_to_edit'] ) : '';

		} else {
			$feed_id = $feed_id[0];

		}
		$stock_status        = isset( $_POST['stock_status'] ) ? map_deep( $_POST['stock_status'], 'sanitize_text_field' ) : array();
		$sale_country        = isset( $_POST['sale_country'] ) ? sanitize_text_field( $_POST['sale_country'] ) : '';
		$sel_google_cats     = isset( $_POST['sel_google_cats'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sel_google_cats'] ) ) : array();
		$prod_attr           = isset( $_POST['prod_attr'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['prod_attr'] ) ) : '';
		$google_attr         = isset( $_POST['google_attr'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['google_attr'] ) ) : '';
		$feed_file_type      = isset( $_POST['feed_file_type'] ) ? sanitize_text_field( $_POST['feed_file_type'] ) : '';
		$currency_conversion = isset( $_POST['currency_conversion'] ) ? sanitize_text_field( $_POST['currency_conversion'] ) : '';
		$featured            = isset( $_POST['featured'] ) ? sanitize_text_field( $_POST['featured'] ) : '';
		$stock_check         = isset( $_POST['stock_check'] ) ? sanitize_text_field( $_POST['stock_check'] ) : '';
		$stock_quantity      = isset( $_POST['stock_quantity'] ) ? sanitize_text_field( $_POST['stock_quantity'] ) : '';
		$prod_sold_check     = isset( $_POST['prod_sold_check'] ) ? sanitize_text_field( $_POST['prod_sold_check'] ) : '';
		$sold_quantity       = isset( $_POST['sold_quantity'] ) ? sanitize_text_field( $_POST['sold_quantity'] ) : '';
		$chunk               = isset( $_POST['chunk'] ) ? sanitize_text_field( $_POST['chunk'] ) : '';
		$is_edit_project     = isset( $_POST['is_edit_project'] ) ? sanitize_text_field( $_POST['is_edit_project'] ) : '';
		$file_to_edit        = isset( $_POST['file_to_edit'] ) ? sanitize_text_field( $_POST['file_to_edit'] ) : '';
		$include_variation   = isset( $_POST['include_variation'] ) ? sanitize_text_field( $_POST['include_variation'] ) : '';
		$enable_sync         = isset( $_POST['sync_fb_enable'] ) ? sanitize_text_field( $_POST['sync_fb_enable'] ) : false;
		$fb_catalog_id       = isset( $_POST['sync_catalog'] ) ? sanitize_text_field( $_POST['sync_catalog'] ) : '';
		$us_country_check    = isset( $_POST['elex_sync_to_fb_for_us'] ) ? sanitize_text_field( $_POST['elex_sync_to_fb_for_us'] ) : '';

		

		$feed_report = $this->elex_fpf_create_project( $currency_code, $project_title, $project_desc, $sale_country, $sel_google_cats, $product_ids, $prod_attr, $google_attr, $include_variation, $exclude_ids, $condition, $prepend_attr, $append_attr, $feed_file_type, $currency_conversion, $featured, $stock_check, $stock_quantity, $prod_sold_check, $sold_quantity, $prod_vendors, $stock_status, $last_chunk, $chunk, $more_than_hundred, $is_edit_project, $file_to_edit, $enable_sync, $fb_catalog_id );



		$start_filter                                    = array();
		$start_filter['name']                            = $project_title;
		$start_filter['description']                     = $project_desc;
		$start_filter['default_category_chosen']         = $default_category_chosen;
		$start_filter['refresh_schedule']                = isset( $_POST['refresh_schedule'] ) ? sanitize_text_field( $_POST['refresh_schedule'] ) : '';
		$start_filter['refresh_hour']                    = isset( $_POST['refresh_hour'] ) ? sanitize_text_field( $_POST['refresh_hour'] ) : '';
		$start_filter['include_variation']               = isset( $_POST['include_variation'] ) ? sanitize_text_field( $_POST['include_variation'] ) : '';
		$start_filter['featured']                        = $featured;
		$start_filter['sale_country']                    = $sale_country;
		$start_filter['currency_conversion']             = $currency_conversion;
		$start_filter['currency_conversion_code']        = $currency_code;
		$start_filter['feed_file_type']                  = $feed_file_type;
		$start_filter['refresh_days']                    = ( isset( $_POST['refresh_days'] ) && is_array( $_POST['refresh_days'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['refresh_days'] ) ) : array( strtolower( current_time( 'l' ) ) );
		$start_filter['sync_fb_enable']                  = $enable_sync;
		$start_filter['elex_sync_to_fb_for_us']          = $us_country_check;
		$category_select                                 = array();
		$category_select['ids']                          = $product_ids;
		$category_select['sel_google_cats']              = $sel_google_cats;
		$category_select['categories_choosen']           = ( isset( $_POST['categories_choosen'] ) && is_array( $_POST['categories_choosen'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['categories_choosen'] ) ) : '';
		$category_select['selected_products']            = $selected_products;
		$category_select['selected_google_product_cats'] = $selected_google_product_cats;
		$attribute_map                                   = array();
		$attribute_map['google_attr']                    = $google_attr;
		$attribute_map['prod_attr']                      = $prod_attr;
		if ( ! empty( $condition ) ) {
			$attribute_map['conditions'] = $condition;
		}
		if ( ! empty( $prepend_attr ) ) {
			$attribute_map['prepend_attr'] = $prepend_attr;
		}
		if ( ! empty( $append_attr ) ) {
			$attribute_map['append_attr'] = $append_attr;
		}
		$filtering_options                    = array();
		$filtering_options['exclude_ids']     = $exclude_ids;
		$filtering_options['stock_check']     = $stock_check;
		$filtering_options['stock_quantity']  = $stock_quantity;
		$filtering_options['prod_sold_check'] = $prod_sold_check;
		$filtering_options['sold_quantity']   = $sold_quantity;
		$filtering_options['prod_vendor']     = $prod_vendors;
		$filtering_options['stock_status']    = $stock_status;

		$manage_feed_data                   = array();
		$manage_feed_data['pause_schedule'] = 'ready';
		if ( isset( $_POST['is_edit_project'] ) && 'true' !== $_POST['is_edit_project'] ) {
			$manage_feed_data['created_date'] = current_time( 'd-m-Y H:i:s' );
		} else {
			$prev_manage_feed_data            = json_decode( stripslashes( elex_fpf_get_feed_data( $feed_id, 'manage_feed_data' )[0]['feed_meta_content'] ), true );
			$manage_feed_data['created_date'] = $prev_manage_feed_data['created_date'];
		}
		$manage_feed_data['modified_date']          = current_time( 'd-m-Y H:i:s' );
		$manage_feed_data['file']                   = $project_title . '.' . $feed_file_type;
		$manage_feed_data['name']                   = $project_title;
		$manage_feed_data['refresh_schedule']       = $start_filter['refresh_schedule'];
		$manage_feed_data['refresh_hour']           = $start_filter['refresh_hour'];
		$manage_feed_data['refresh_days']           = $start_filter['refresh_days'];
		$manage_feed_data['sync_fb_enable']         = $enable_sync;
		$manage_feed_data['sync_catalog']           = $fb_catalog_id;
		$manage_feed_data['elex_sync_to_fb_for_us'] = $us_country_check;
		if ( $more_than_hundred && ! $last_chunk ) {
			$temp_report_data = elex_fpf_get_feed_data( $feed_id, 'temp_report_data' );
			if ( ! empty( $temp_report_data ) ) {
				$temp_report_data = json_decode( stripslashes( $temp_report_data[0]['feed_meta_content'] ), true );

				$update_report_data                    = array();
				$update_report_data['simple']          = array_merge_recursive( $temp_report_data['simple'], $feed_report['simple'] );
				$update_report_data['variation']       = array_merge_recursive( $temp_report_data['variation'], $feed_report['variation'] );
				$update_report_data['total_simple']    = $temp_report_data['total_simple'] + $feed_report['total_simple'];
				$update_report_data['total_variation'] = $temp_report_data['total_variation'] + $feed_report['total_variation'];
				elex_fpf_update_feed( $feed_id, 'temp_report_data', $update_report_data );

			} else {
				elex_fpf_insert_feed( $feed_id, 'temp_report_data', $feed_report );
			}

			die( json_encode( array( 'status' => 'need_to_generate_feed' ) ) );

		}
		$temp_report_data   = elex_fpf_get_feed_data( $feed_id, 'temp_report_data' );
		$update_report_data = array();
		if ( ! empty( $temp_report_data ) ) {
			$temp_report_data                      = json_decode( stripslashes( $temp_report_data[0]['feed_meta_content'] ), true );
			$update_report_data['simple']          = array_merge_recursive( $temp_report_data['simple'], $feed_report['simple'] );
			$update_report_data['variation']       = array_merge_recursive( $temp_report_data['variation'], $feed_report['variation'] );
			$update_report_data['total_simple']    = $temp_report_data['total_simple'] + $feed_report['total_simple'];
			$update_report_data['total_variation'] = $temp_report_data['total_variation'] + $feed_report['total_variation'];
			global $wpdb;
			$table_name = $wpdb->prefix . 'fpf_feeds';
			$id         = $feed_id;
			$meta_key   = 'temp_report_data';
			elexFpfWPFluent()->table( 'fpf_feeds' )
			->where( 'feed_id', '=', $id )
			->where( 'feed_meta_key', '=', $meta_key )
			->delete();
		} else {
		

			$update_report_data = $feed_report;
		}
		$feed_reports = array();
		$current_time = current_time( 'd-m-Y H:i:s' );
		
		if ( isset( $_POST['is_edit_project'] ) && 'true' === $_POST['is_edit_project'] ) {
			$prev_report_data              = json_decode( stripslashes( elex_fpf_get_feed_data( $feed_id, 'report_data' )[0]['feed_meta_content'] ), true );
			$feed_reports                  = $prev_report_data;
			$feed_reports[ $current_time ] = $update_report_data;
			elex_fpf_update_feed( $feed_id, 'start_filter', $start_filter );
			elex_fpf_update_feed( $feed_id, 'category_select', $category_select );
			elex_fpf_update_feed( $feed_id, 'attribute_map', $attribute_map );
			elex_fpf_update_feed( $feed_id, 'filtering_options', $filtering_options );
			elex_fpf_update_feed( $feed_id, 'manage_feed_data', $manage_feed_data );
			elex_fpf_update_feed( $feed_id, 'report_data', $feed_reports );

		} else {
			$feed_reports[ $current_time ] = $update_report_data;
			elex_fpf_insert_feed( $feed_id, 'start_filter', $start_filter );
			elex_fpf_insert_feed( $feed_id, 'category_select', $category_select );
			elex_fpf_insert_feed( $feed_id, 'attribute_map', $attribute_map );
			elex_fpf_insert_feed( $feed_id, 'filtering_options', $filtering_options );
			elex_fpf_insert_feed( $feed_id, 'manage_feed_data', $manage_feed_data );
			elex_fpf_insert_feed( $feed_id, 'report_data', $feed_reports );
		}
		$simple_excluded    = 'no';
		$variation_excluded = 'no';
		if ( isset( $feed_reports[ $current_time ] ) ) {
			if ( ! empty( $feed_reports[ $current_time ]['simple'] ) ) {
				$simple_excluded = 'yes';
			}
			if ( ! empty( $feed_reports[ $current_time ]['variation'] ) ) {
				$variation_excluded = 'yes';
			}
		}
		$feed_success = array(
			'status'             => 'done',
			'feed_id'            => $feed_id,
			'current_time'       => $current_time,
			'simple_excluded'    => $simple_excluded,
			'variation_excluded' => $variation_excluded,
			'num_prod'           => $num_of_product, 
		);
		die( wp_json_encode( $feed_success ) );
	}

	public function elex_fpf_required_attr_to_exclude_prod() {
		return array(
			'id',
			'title',
			'description',
			'link',
			'image_link',
			'availability',
			'price',
			

		);
	}

	public function elex_fpf_create_project( $currency_code, $project_title, $project_desc, $sale_country, $sel_google_cats, $product_ids, $prod_attr, $google_attr, $include_variation, $exclude_ids, $condition, $prepend_attr, $append_attr, $mime_type, $currency_conversion, $featured, $stock_check, $stock_quantity, $prod_sold_check, $sold_quantity, $prod_vendor, $stock_status, $last_chunk = false, $chunk = 0, $more_than_hundred = false, $is_edit_project = '', $file_to_edit = '', $enable_sync = false, $fb_catalog_id = '' ) {
		$seperated_value = ',';
		$file_mime_type  = '.csv';
		if ( 'tsv' === $mime_type ) {
			$seperated_value = "\t";
			$file_mime_type  = '.tsv';
		}
		$required_attr_to_exclude_prod = $this->elex_fpf_required_attr_to_exclude_prod();
		$feed_report_products          = array(
			'simple'    => array(),
			'variation' => array(),
		);
		$total_simple                  = 0;
		$total_variation               = 0;
		$upload_dir                    = wp_upload_dir();
		$base                          = $upload_dir['basedir'];
		$path                          = $base . '/elex-facebook-feed/';
		if ( 'true' !== $is_edit_project && '' !== $is_edit_project ) {
			$result = elexFpfWPFluent()->table( 'fpf_feeds' )->where( 'feed_meta_key', 'manage_feed_data' )->get();
			$result = json_decode( json_encode( $result ), true );
			foreach ( $result as $index => $value ) {
				$saved_feed_data = $value['feed_meta_content'];
				$saved_feed_data = json_decode( $saved_feed_data, true );
				if ( str_replace( ' ', '_', $saved_feed_data['name'] ) === $project_title ) {
					die( 'same_name' );
				}
			}
		} else {
			if ( ! empty( $file_to_edit ) ) {
				$manage_feed_data = json_decode( elex_fpf_get_feed_data( $file_to_edit, 'manage_feed_data' )[0]['feed_meta_content'], true );
				if ( file_exists( $path . $manage_feed_data['file'] ) ) {
					unlink( $path . $manage_feed_data['file'] );
				}
			}
		}
		$original_project_title = $project_title;
		if ( $more_than_hundred ) {
			$project_title = $project_title . '_chunk' . $chunk;
		}
		$file = $path . '/' . $project_title . $file_mime_type;
		if ( ! file_exists( $path ) ) {
			wp_mkdir_p( $path );
		}
		$csv              = array();
		$ship_tax_details = array();
		$ship_or_tax      = array();
		foreach ( $google_attr as $key => $value ) {
			if ( substr( $value, 0, 9 ) === 'shipping-' ) {
				array_push( $ship_tax_details, $value );
				if ( ! in_array( 'shipping', $ship_or_tax ) ) {
					array_push( $ship_or_tax, 'shipping' );
				}
			} elseif ( substr( $value, 0, 3 ) === 'tax' ) {
				array_push( $ship_tax_details, $value );
				if ( ! in_array( 'tax', $ship_or_tax ) ) {
					array_push( $ship_or_tax, 'tax' );
				}
			} elseif ( substr( $value, 0, 14 ) === 'product_detail' ) {
				array_push( $ship_tax_details, $value );
				if ( ! in_array( 'product_detail', $ship_or_tax ) ) {
					array_push( $ship_or_tax, 'product_detail' );
				}
			} elseif ( substr( $value, 0, 14 ) === 'product_detail' ) {
				array_push( $ship_tax_details, $value );
				if ( ! in_array( 'product_detail', $ship_or_tax ) ) {
					array_push( $ship_or_tax, 'product_detail' );
				}
			} elseif ( substr( $value, 0, 17 ) === 'subscription_cost' ) {
				array_push( $ship_tax_details, $value );
				if ( ! in_array( 'subscription_cost', $ship_or_tax ) ) {
					array_push( $ship_or_tax, 'subscription_cost' );
				}
			} else {
				if ( 'importer_addr_street1' == $value || 'importer_addr_street2' == $value || 'importer_addr_region' == $value || 'importer_addr_postal_code' == $value || 'importer_addr_city' == $value || 'manufacturer_name' == $value || 'manufacturer_address' == $value || 'importer_addr_country' == $value ) {
					continue;
				}
				$csv[] = $value;
			}
		}
		if ( 'IN' == $sale_country ) {
			$csv[] = 'importer_address' ;
			$csv[] = 'manufacturer_info' ; 
		}
	
		if ( ! empty( $ship_or_tax ) ) {
			if ( in_array( 'shipping', $ship_or_tax ) ) {
				$csv[] = 'shipping' ;
			}
			if ( in_array( 'tax', $ship_or_tax ) ) {
				$csv[] = 'tax' ;
			}
			if ( in_array( 'product_detail', $ship_or_tax ) ) {
				$csv[] = 'product_detail' ;
			}
			if ( in_array( 'subscription_cost', $ship_or_tax ) ) {
				$csv[] = 'subscription_cost' ;
			}
		}   
		$csv_handler = fopen( $file, 'w' );

		fputcsv( $csv_handler, $csv );


		$product_attributes = $this->elex_fpf_get_product_attributes();
		$updated_ids        = array();
		$add_items          = '';
		$prefix             = '';
		$temp_csv           = array();
		
		
		foreach ( $product_ids as $key => $val ) {
			$temp_cat          = explode( '-', $key );
			$google_cat        = trim( $temp_cat[0] );
			$importer_address  = array();
			$manufacturer_info = array();
			foreach ( $val as $ids ) {
				if ( ! in_array( $ids, $updated_ids ) ) {
					array_push( $updated_ids, $ids );
				} else {
					continue;
				}
				$vendor_check = false;
				if ( ( ! is_array( $prod_vendor ) || empty( $prod_vendor ) ) || in_array( get_post_field( 'post_author', $ids ), $prod_vendor ) ) {
					$vendor_check = true;
				}
				$skip_prod = false;
				if ( $enable_sync && 'false' != $enable_sync ) {
					$product          = wc_get_product( $ids );
					$prod_sync_enable = $product->get_meta( '_elex_fpf_sync_enable' );
					if ( 'disable' == $prod_sync_enable ) {
						$skip_prod = true;
					}
				}
				if ( ( ! is_array( $exclude_ids ) || ! in_array( $ids, $exclude_ids ) ) && $vendor_check && ! $skip_prod ) {
					$product = wc_get_product( $ids );
					if ( ! $product ) {
						continue;
					}
					$product_details = $product->get_data();
				
					$is_featured = true;
					if ( 'true' === $featured ) {
						$is_featured = $product->is_featured();
					}

					if ( elex_fb_premium() && $product->is_type( 'variable' ) && 'true' === $include_variation && $is_featured ) {
						$required_attr_to_exclude_prod[] = 'item_group_id';
						$variable_ids                    = $product->get_children();
						foreach ( $variable_ids as $variations ) {
							$variable_prod = wc_get_product( $variations );

							$check_stock_and_sold = $this->elex_fpf_check_stock_and_sold_quantity( $variable_prod, $stock_check, $stock_quantity, $prod_sold_check, $sold_quantity, $stock_status );
							if ( ( ! is_array( $exclude_ids ) || ! in_array( $variations, $exclude_ids ) ) ) {
								$variable_product_details = $variable_prod->get_data();
								$vari_attributes          = $variable_product_details['attributes'];
								$vari_attributes_title    = $variable_product_details['attribute_summary'];
								$vari_attributes_title    = explode( ',', $vari_attributes_title );
								$shipping_data            = array();
								$tax_data                 = array();
								$product_detail_data      = array();
								$subscription_cost_data   = array();
								
								$flag_gtin_not_present  = 0;
								$flag_brand_not_present = 0;
		
								$reached_gtin = 0;
							
		
								$flag_mpn_not_present = 0;
								$reached_mpn          = 0;
								$reached_brand        = 0;

								$google_attr_count = count( $google_attr );
								for ( $i = 0; $i < $google_attr_count; $i++ ) {
									$map_prod_attr_val    = '';
									$value_from_condition = '';
									if ( isset( $condition[ $i ] ) ) {
										$value_from_condition = $this->elex_fpf_get_value_from_condition_variable( $condition[ $i ], $google_attr[ $i ], $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, '', $add_items, $currency_conversion, $sale_country );
									}
									if ( $value_from_condition ) {
										$map_prod_attr_val = $value_from_condition;
									} else {
										
										$map_prod_attr_val = $this->get_vari_product_attribute_value( $prod_attr[ $i ], $google_attr[ $i ], $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, '', $product_details, $variable_product_details, '', $currency_conversion, $sale_country );
										$prepend_text      = '';
										if ( isset( $prepend_attr[ $i ] ) ) {
											foreach ( $prepend_attr[ $i ] as $prepend_key => $prepend_value ) {
												
												$prep_val = $this->get_vari_product_attribute_value( $prepend_value[0], $google_attr[ $i ], $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, '', $product_details, $variable_product_details, '', $currency_conversion, $sale_country );

												$prepend_result = $this->elex_fpf_prepend_append_value( $prep_val, $prepend_value[1], 'prepend' );
												$prepend_text  .= $prepend_result;
											}
											$map_prod_attr_val = $prepend_text . $map_prod_attr_val;
										}
										$append_text = '';
										if ( isset( $append_attr[ $i ] ) ) {
											foreach ( $append_attr[ $i ] as $append_key => $append_value ) {
												 
												$app_val = $this->get_vari_product_attribute_value( $append_value[0], $google_attr[ $i ], $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, '', $product_details, $variable_product_details, '', $currency_conversion, $sale_country );

												$append_result = $this->elex_fpf_prepend_append_value( $app_val, $append_value[1], 'append' );
												$append_text  .= $append_result;
											}
											$map_prod_attr_val = $map_prod_attr_val . $append_text;
										}
									}

									if ( ! $check_stock_and_sold ) {
										$feed_report_products['variation']['stock'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
										continue;
									}
									if ( 'post_content' === $prod_attr[ $i ] && $map_prod_attr_val ) {
										if ( strtoupper( $map_prod_attr_val ) == $map_prod_attr_val ) {
											$feed_report_products['variation']['description'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											continue;
										}
									}
									if ( 'price' === $google_attr[ $i ] && $map_prod_attr_val ) {
										$map_prod_attr_val = round( $map_prod_attr_val, 2 );
										$map_prod_attr_val = $map_prod_attr_val . ' ' . $currency_code;
									}
									if ( 'shipping-price' === $google_attr[ $i ] ) {
										$shipping_data['price'] = $map_prod_attr_val;
										continue;
									}
									if ( 'shipping-country' === $google_attr[ $i ] ) {
										$shipping_data['country'] = $map_prod_attr_val;
										continue;
									}
									if ( 'shipping-region' === $google_attr[ $i ] ) {
										$shipping_data['region'] = $map_prod_attr_val;
										continue;
									}
									if ( 'shipping-service' === $google_attr[ $i ] ) {
										$shipping_data['service'] = $map_prod_attr_val;
										continue;
									}
									if ( 'tax-rate' === $google_attr[ $i ] ) {
										$tax_data['rate'] = $map_prod_attr_val;
										continue;
									}
									if ( 'tax-country' === $google_attr[ $i ] ) {
										$tax_data['country'] = $map_prod_attr_val;
										continue;
									}
									if ( 'tax-region' === $google_attr[ $i ] ) {
										$tax_data['region'] = $map_prod_attr_val;
										continue;
									}
									if ( 'tax-tax_ship' === $google_attr[ $i ] ) {
										$tax_data['tax_ship'] = $map_prod_attr_val;
										continue;
									}
									if ( 'product_detail-section_name' === $google_attr[ $i ] ) {
										$product_detail_data['section_name'] = $map_prod_attr_val;
										continue;
									}
									if ( 'product_detail-attribute_name' === $google_attr[ $i ] ) {
										$product_detail_data['attribute_name'] = $map_prod_attr_val;
										continue;
									}
									if ( 'product_detail-attribute_value' === $google_attr[ $i ] ) {
										$product_detail_data['attribute_value'] = $map_prod_attr_val;
										continue;
									}
									if ( 'subscription_cost-period' === $google_attr[ $i ] ) {
										$subscription_cost_data['period'] = $map_prod_attr_val;
										continue;
									}
									if ( 'subscription_cost-period_length' === $google_attr[ $i ] ) {
										$subscription_cost_data['period_length'] = $map_prod_attr_val;
										continue;
									}
									if ( 'subscription_cost-amount' === $google_attr[ $i ] ) {
										$subscription_cost_data['amount'] = $map_prod_attr_val;
										continue;
									}
									if ( 'brand' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$flag_brand_not_present = 1;
										}
										$reached_brand = 1;
									}
									if ( 'gtin' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$flag_gtin_not_present = 1;    
											
										}
										$reached_gtin = 1;
									}
									
									if ( 'mpn' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$flag_mpn_not_present = 1;

										}
										$reached_mpn = 1;
									}

									if ( $reached_gtin && $reached_mpn && $reached_brand ) {
										if ( $flag_gtin_not_present && $flag_mpn_not_present && $flag_brand_not_present ) {
											$feed_report_products['variation']['brand'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											$feed_report_products['variation']['gtin'][]  = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											$feed_report_products['variation']['mpn'][]   = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											$temp_csv[]                                   = '';
										}
									}
									if ( 'origin_country' === $google_attr[ $i ] && ! $map_prod_attr_val ) {
										$feed_report_products['variation']['origin_country'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
										continue;
									}
									if ( 'importer_name' === $google_attr[ $i ] && ! $map_prod_attr_val ) {
										$feed_report_products['variation']['importer_name'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
										continue;
									}
									if ( 'quantity_to_sell_on_facebook' === $google_attr[ $i ] ) {
										if ( 'US' == $sale_country && ! $map_prod_attr_val ) {
										$feed_report_products['variation']['quantity_to_sell_on_facebook'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
										continue;
										}
									}
									if ( 'size' === $google_attr[ $i ] ) {
										if ( 'US' == $sale_country && ! $map_prod_attr_val ) {
											$feed_report_products['variation']['size'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
											continue;
										}
									}
									
									if ( 'importer_addr_street1' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$feed_report_products['variation']['street1'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											continue;
										}
										$importer_address['street1'] = $map_prod_attr_val;
										continue;
									}
									if ( 'importer_addr_street2' === $google_attr[ $i ] ) {
										$importer_address['street2'] = $map_prod_attr_val;
										continue;
		
									}
									if ( 'importer_addr_city' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$feed_report_products['variation']['city'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											continue;
										}
										$importer_address['city'] = $map_prod_attr_val;
										continue;
		
									}
									if ( 'importer_addr_region' === $google_attr[ $i ] ) {
										$importer_address['region'] = $map_prod_attr_val;
										continue;
		
									}
									if ( 'importer_addr_postal_code' === $google_attr[ $i ] ) {
										$importer_address['postal_code'] = $map_prod_attr_val;
										continue;
									}
									if ( 'importer_addr_country' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$feed_report_products['variation']['country'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											continue;
										}
										$importer_address['country'] = $map_prod_attr_val;
										continue;
									}
		
									if ( 'manufacturer_name' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$feed_report_products['variation']['manufacturer_name'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											continue;
										}
										$manufacturer_info[ $google_attr[ $i ] ] = $map_prod_attr_val;
										continue;
									}
									if ( 'manufacturer_address' === $google_attr[ $i ] ) {
										if ( ! $map_prod_attr_val ) {
											$feed_report_products['variation']['manufacturer_address'][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
											continue;
										}
										$manufacturer_info[ $google_attr[ $i ] ] = $map_prod_attr_val;
										continue;
									}

						
									if ( ! $map_prod_attr_val && in_array( $google_attr[ $i ], $required_attr_to_exclude_prod ) ) {
										$feed_report_products['variation'][ $google_attr[ $i ] ][] = $variations . '-' . htmlspecialchars( $variable_prod->get_formatted_name() );
										$temp_csv[] = '';
										break;
									}
									$temp_csv[] = htmlspecialchars( $map_prod_attr_val );                             
								}    
								if ( 'IN' == $sale_country && ! empty( $importer_address ) ) {
									$json_importer = json_encode( $importer_address );
		
									$temp_csv[] = $json_importer ;
									
									$importer_address = [];
								}
								if ( 'IN' == $sale_country && ! empty( $manufacturer_info ) ) {
									$json_importer = $manufacturer_info['manufacturer_name'] . ' , ' . $manufacturer_info['manufacturer_address'] ;
		
									$temp_csv[] = $json_importer ;
								
									$manufacturer_info = [];
								}
						

								$temp_csv = $this->elex_get_tax_and_ship_details_csv( $shipping_data, $tax_data, $product_detail_data, $subscription_cost_data, $temp_csv, $seperated_value, $currency_code );

								if ( $temp_csv ) {
									fputcsv( $csv_handler, $temp_csv );
									$temp_csv = array();
									$total_variation++;
								}
							}
						}
					} elseif ( $product->is_type( 'simple' ) && $is_featured ) {
						$shipping_data          = array();
						$tax_data               = array();
						$product_detail_data    = array();
						$subscription_cost_data = array();
						$flag_gtin_not_present  = 0;
						$flag_brand_not_present = 0;
						$flag_mpn_not_present   = 0;

						$reached_gtin  = 0;
						$reached_brand = 0;
						$reached_mpn   = 0;

				
						$google_attr_count = count( $google_attr );
						
						for ( $i = 0; $i < $google_attr_count; $i++ ) {
							
							$map_prod_attr_val    = '';
							$value_from_condition = '';
							if ( isset( $condition[ $i ] ) ) {
								$value_from_condition = $this->elex_fpf_get_value_from_condition_simple( $condition[ $i ], $google_attr[ $i ], $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, '', $add_items, $currency_conversion, $sale_country );
								
							}
							if ( $value_from_condition ) {
								$map_prod_attr_val = $value_from_condition;
							} else {
								
								$prod_attr_val   = isset( $prod_attr[ $i ] ) ? $prod_attr[ $i ] : '';
								$google_attr_val = isset( $google_attr[ $i ] ) ? $google_attr[ $i ] : '';

								$map_prod_attr_val = $this->elex_fpf_get_simple_product_attr_values( $prod_attr_val, $google_attr_val, $ids, $product, $product_details, '', $google_cat, $product_attributes, '', $currency_conversion, $sale_country );
								$prepend_text      = '';
								if ( isset( $prepend_attr[ $i ] ) ) {
									foreach ( $prepend_attr[ $i ] as $prepend_key => $prepend_value ) {
										
										$prep_val = $this->elex_fpf_get_simple_product_attr_values( $prepend_value[0], $google_attr[ $i ], $ids, $product, $product_details, '', $google_cat, $product_attributes, '', $currency_conversion, $sale_country );

										$prepend_result = $this->elex_fpf_prepend_append_value( $prep_val, $prepend_value[1], 'prepend' );
										$prepend_text  .= $prepend_result;
									}
										$map_prod_attr_val = $prepend_text . $map_prod_attr_val;
								}
								$append_text = '';
								if ( isset( $append_attr[ $i ] ) ) {
									foreach ( $append_attr[ $i ] as $append_key => $append_value ) {
										
										$app_val = $this->elex_fpf_get_simple_product_attr_values( $append_value[0], $google_attr[ $i ], $ids, $product, $product_details, '', $google_cat, $product_attributes, '', $currency_conversion, $sale_country );

										$append_result = $this->elex_fpf_prepend_append_value( $app_val, $append_value[1], 'append' );
										$append_text  .= $append_result;
									}
										$map_prod_attr_val = $map_prod_attr_val . $append_text;
								}
							}
							if ( $stock_check || $stock_quantity || $prod_sold_check || $sold_quantity ) {
								$check_stock_and_sold = $this->elex_fpf_check_stock_and_sold_quantity( $product, $stock_check, $stock_quantity, $prod_sold_check, $sold_quantity, $stock_status );
								if ( $check_stock_and_sold ) {
									$feed_report_products['simple']['stock'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									break;
								}
							}
							if ( 'post_content' === $prod_attr_val && $map_prod_attr_val ) {
								if ( strtoupper( $map_prod_attr_val ) == $map_prod_attr_val ) {
									$feed_report_products['simple']['description'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
							}	

							if ( 'price' === $google_attr[ $i ] && $map_prod_attr_val ) {
								$map_prod_attr_val = round( $map_prod_attr_val, 2 );
								$map_prod_attr_val = $map_prod_attr_val . ' ' . $currency_code;
							}
							if ( 'shipping-price' === $google_attr[ $i ] ) {
								
								$shipping_data['price'] = $map_prod_attr_val;
								continue;
							}
							if ( 'shipping-country' === $google_attr[ $i ] ) {
								$shipping_data['country'] = $map_prod_attr_val;
								continue;
							}
							if ( 'shipping-region' === $google_attr[ $i ] ) {
								$shipping_data['region'] = $map_prod_attr_val;
								continue;
							}
							if ( 'shipping-service' === $google_attr[ $i ] ) {
								$shipping_data['service'] = $map_prod_attr_val;
								continue;
							}
							if ( 'tax-rate' === $google_attr[ $i ] ) {
								$tax_data['rate'] = $map_prod_attr_val;
								continue;
							}
							if ( 'tax-country' === $google_attr[ $i ] ) {
								$tax_data['country'] = $map_prod_attr_val;
								continue;
							}
							if ( 'tax-region' === $google_attr[ $i ] ) {
								$tax_data['region'] = $map_prod_attr_val;
								continue;
							}
							if ( 'tax-tax_ship' === $google_attr[ $i ] ) {
								$tax_data['tax_ship'] = $map_prod_attr_val;
								continue;
							}
							if ( 'product_detail-section_name' === $google_attr[ $i ] ) {
								$product_detail_data['section_name'] = $map_prod_attr_val;
								continue;
							}
							if ( 'product_detail-attribute_name' === $google_attr[ $i ] ) {
								$product_detail_data['attribute_name'] = $map_prod_attr_val;
								continue;
							}
							if ( 'product_detail-attribute_value' === $google_attr[ $i ] ) {
								$product_detail_data['attribute_value'] = $map_prod_attr_val;
								continue;
							}
							if ( 'subscription_cost-period' === $google_attr[ $i ] ) {
								$subscription_cost_data['period'] = $map_prod_attr_val;
								continue;
							}
							if ( 'subscription_cost-period_length' === $google_attr[ $i ] ) {
								$subscription_cost_data['period_length'] = $map_prod_attr_val;
								continue;
							}
							if ( 'subscription_cost-amount' === $google_attr[ $i ] ) {
								$subscription_cost_data['amount'] = $map_prod_attr_val;
								continue;
							}
							
							if ( 'brand' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$flag_brand_not_present = 1;

								}
								$reached_brand = 1;
							}
							if ( 'gtin' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$flag_gtin_not_present = 1;

								}
								$reached_gtin = 1;
							}
							
							if ( 'mpn' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$flag_mpn_not_present = 1;

								}
								$reached_mpn = 1;
							}

							if ( $reached_gtin && $reached_mpn && $reached_brand ) {
								if ( $flag_gtin_not_present && $flag_mpn_not_present && $flag_brand_not_present ) {
									$reached_brand                             = 0;
									$reached_mpn                               = 0;
									$reached_gtin                              = 0;
									$feed_report_products['simple']['brand'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									$feed_report_products['simple']['gtin'][]  = $ids . '-' . htmlspecialchars( $product->get_title() );
									$feed_report_products['simple']['mpn'][]   = $ids . '-' . htmlspecialchars( $product->get_title() );
									$temp_csv                                  = array() ;
									
								}
							}
		
							if ( 'origin_country' === $google_attr[ $i ] && ! $map_prod_attr_val ) {
								$feed_report_products['simple']['origin_country'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
								continue;
							}
							if ( 'importer_name' === $google_attr[ $i ] && ! $map_prod_attr_val ) {
								$feed_report_products['simple']['importer_name'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
								continue;
							}
							if ( 'quantity_to_sell_on_facebook' === $google_attr[ $i ] ) {
								if ( 'US' == $sale_country && ! $map_prod_attr_val ) {
								$feed_report_products['simple']['quantity_to_sell_on_facebook'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
								continue;
								}
								$sell_usa = $map_prod_attr_val;
							}
							if ( 'size' === $google_attr[ $i ] ) {
								if ( 'US' == $sale_country && ! $map_prod_attr_val ) {
									$feed_report_products['simple']['size'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
								$size_usa = $map_prod_attr_val;
							}
							if ( 'importer_name' === $google_attr[ $i ] && ! $map_prod_attr_val ) {
								$feed_report_products['simple']['importer_name'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
								continue;
							}

							if ( 'importer_addr_street1' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$feed_report_products['simple']['street1'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
								$importer_address['street1'] = $map_prod_attr_val;
								continue;
							}
							if ( 'importer_addr_street2' === $google_attr[ $i ] ) {
								$importer_address['street2'] = $map_prod_attr_val;
								continue;

							}
							if ( 'importer_addr_city' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$feed_report_products['simple']['city'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
								$importer_address['city'] = $map_prod_attr_val;
								continue;

							}

							if ( 'importer_addr_region' === $google_attr[ $i ] ) {
								$importer_address['region'] = $map_prod_attr_val;
								continue;

							}
							if ( 'importer_addr_postal_code' === $google_attr[ $i ] ) {
								$importer_address['postal_code'] = $map_prod_attr_val;
								continue;
							}
							if ( 'importer_addr_country' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$feed_report_products['simple']['country'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
								$importer_address['country'] = $map_prod_attr_val;
								continue;
							}
							if ( 'manufacturer_name' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$feed_report_products['simple']['manufacturer_name'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
								$manufacturer_info[ $google_attr[ $i ] ] = $map_prod_attr_val;
								continue;
							}
							if ( 'manufacturer_address' === $google_attr[ $i ] ) {
								if ( ! $map_prod_attr_val ) {
									$feed_report_products['simple']['manufacturer_address'][] = $ids . '-' . htmlspecialchars( $product->get_title() );
									continue;
								}
								$manufacturer_info[ $google_attr[ $i ] ] = $map_prod_attr_val;
								continue;
							}

						
							if ( ! $map_prod_attr_val && in_array( $google_attr[ $i ], $required_attr_to_exclude_prod ) && 'item_group_id' !== $google_attr[ $i ] ) {
										$feed_report_products['simple'][ $google_attr[ $i ] ][] = $ids . '-' . htmlspecialchars( $product->get_title() );
										$temp_csv[] = '';
										// break; 
							}
						

							if ( 'item_group_id' !== $google_attr[ $i ] ) {
								$map_prod_attr_val = str_replace( ',', '-', $map_prod_attr_val );
								$map_prod_attr_val = trim( preg_replace( '/\s+/', ' ', $map_prod_attr_val ) );

								$temp_csv[] = addslashes( $map_prod_attr_val );
							} 
							if ( 'item_group_id' == $google_attr[ $i ] ) {
								$temp_csv[] = $map_prod_attr_val ;
							} 
						}
						if ( 'IN' == $sale_country && ! empty( $importer_address ) ) {
							$json_importer = json_encode( $importer_address );

							$temp_csv[]       = $json_importer ;
							$importer_address = [];
						}
						if ( 'IN' == $sale_country && ! empty( $manufacturer_info ) ) {
							$json_importer = $manufacturer_info['manufacturer_name'] . ' , ' . $manufacturer_info['manufacturer_address'] ;

							$temp_csv[] = $json_importer ;

							$manufacturer_info = [];
						}
						
					
							 
						$temp_csv = $this->elex_get_tax_and_ship_details_csv( $shipping_data, $tax_data, $product_detail_data, $subscription_cost_data, $temp_csv, $seperated_value, $currency_code );

						if ( $temp_csv ) {                          
							fputcsv( $csv_handler, $temp_csv );

							$temp_csv = array();
						
							$total_simple++;
						}
					}
				}
			}
		}


		fclose( $csv_handler );
		$files = '';
		if ( $more_than_hundred && $last_chunk ) {
			$files = array();
			for ( $i = 0;$i <= $chunk;$i++ ) {
				$files[] = $path . '/' . $original_project_title . '_chunk' . $i . $file_mime_type;
			}
		}
		if ( is_array( $files ) ) {
			$file_path = $path . '/' . $original_project_title . $file_mime_type;
			$this->elex_fpf_join_files( $files, $file_path, $file_mime_type );
			for ( $i = 0;$i <= $chunk;$i++ ) {
				unlink( $path . '/' . $original_project_title . '_chunk' . $i . $file_mime_type );
			}
		}
		if ( ( is_array( $files ) || ! $more_than_hundred ) && 'xml' === $mime_type ) {
			$this->elex_fpf_convert_to_xml( $path . '/' . $original_project_title, $project_title, $project_desc, $enable_sync, $fb_catalog_id );
			// unlink( $path . '/' . $original_project_title . '.csv' );
		}
		$feed_report_products['total_simple']    = $total_simple;
		$feed_report_products['total_variation'] = $total_variation;
		return $feed_report_products;
	}



	public function elex_fpf_sync_facebook( $product_data, $project_title, $fb_catalog_id ) {
	
		$upload_product_data = array();
		foreach ( $product_data as $key => $value ) {
			$value['fb_product_category'] = $value['google_product_category'];
			unset( $value['google_product_category'] );
			$upload_product_data[ $key ]['method'] = 'UPDATE';
			$value['title']                        = isset( $value['title'] ) ? html_entity_decode( strip_tags( $value['title'] ) ) : '';
			$value['description']                  = isset( $value['description'] ) ? html_entity_decode( strip_tags( $value['description'] ) ) : '';
			if ( isset( $value['importer_address'] ) && ! empty( $value['importer_address'] ) ) {
				$value['importer_address'] = isset( $value['importer_address'] ) ? json_decode( $value['importer_address'] ) : '';
				$value['importer_address'] = (array) $value['importer_address'] ;
			}
			

			$upload_product_data[ $key ]['data'] = $value; 
		}
		
		$upload_dir = wp_upload_dir();
		$base       = $upload_dir['basedir'];
		$path       = $base . '/elex-facebook-sync-logs/';

		$file = $path . '/log_' . $project_title . '.txt';
		if ( ! file_exists( $path ) ) {
			wp_mkdir_p( $path );
		}
		$sync_log = fopen( $file, 'a' );
		fwrite( $sync_log, "\n" );
		fwrite( $sync_log, 'REQUEST: ' );
		fwrite( $sync_log, current_time( 'd-m-Y H:i:s' ) );
		fwrite( $sync_log, "\n" );
		fwrite( $sync_log, print_r( $upload_product_data, true ) );
		fwrite( $sync_log, "\n" );

		$catalog_access_token = get_option( 'elex_fb_access_token' );
		$request_body         = [
			'headers' => [
				'Authorization' => "Bearer {$catalog_access_token}",
				'Content-type'  => 'application/json',
				'accept'        => 'application/json',
			],
			'body'    => json_encode(
				[
					'allow_upsert' => true,
					'item_type'    => 'PRODUCT_ITEM',
					'requests'     => json_encode( $upload_product_data ),
				]
			),
		];
		

		$items_batch            = "https://graph.facebook.com/v17.0/$fb_catalog_id/items_batch";
		$batch_response         = wp_remote_post( $items_batch, $request_body );
		$batch_response_details = wp_remote_retrieve_body( $batch_response );
		
		$batch_response_details = json_decode( $batch_response_details );
		fwrite( $sync_log, 'RESPONSE: ' );
		fwrite( $sync_log, "\n" );
		fwrite( $sync_log, print_r( $batch_response_details, true ) );
		fwrite( $sync_log, "\n" );
		fwrite( $sync_log, '//////////////////////////////////////////////////////////////////////////////////////////////////' );
		fclose( $sync_log );

		//Error validation while syncing.
		if (isset($batch_response_details->error->message)) {
				$message = $batch_response_details->error->message;
				$type    = $batch_response_details->error->type;
				$code    = $batch_response_details->error->code;
				$this->elex_fpf_error_message_display($type, $code, $message );
		}
	}

	//Function for diplaying error message while syncing.
	public function elex_fpf_error_message_display( $type, $code, $message ) {
			$feed_error_message = array(
				'status'             => 'error',
				'type'               => $type,
				'code'               => $code,
				'message'            => $message,
			);
			die( wp_json_encode( $feed_error_message ) );
	}
	public function elex_fpf_convert_to_xml( $path, $project_title, $project_desc, $enable_sync, $fb_catalog_id ) {
		// Map CSV file to array
		$rows   = array_map( 'str_getcsv', file( $path . '.csv' ) );
		$header = array_shift( $rows );
		$data   = array();
		foreach ( $rows as $row ) {
			if ( count( $header ) > count( $row ) ) {
				$row[] = '';
			}

			if ( count( $header ) === count( $row ) ) {
				$data[] = array_combine( $header, $row );
			}  
		}
		if ( $enable_sync && 'false' != $enable_sync ) {
			$this->elex_fpf_sync_facebook( $data, $project_title, $fb_catalog_id );
			return;
		}

		//Creates XML string and XML document using the DOM
		$xml = new DomDocument( '1.0', 'UTF-8' );
		$rss = $xml->createElement( 'rss' );
		$rss->setAttribute( 'xmlns:g', 'http://base.google.com/ns/1.0' );
		$rss->setAttribute( 'version', '2.0' );
		//Add root node
		$xml->appendChild( $rss );
		$root = $xml->createElement( 'channel' );
		$rss->appendChild( $root );
		//Add title node
		$title_node = $xml->createElement( 'title' );
		$root->appendChild( $title_node );
		$project_title = isset( $project_title ) ? html_entity_decode( strip_tags( $project_title ) ) : '';

		$title_node->appendChild( $xml->createCDATASection( $project_title ) );
		//Add Link node
		$link_node = $xml->createElement( 'link' );
		$root->appendChild( $link_node );
		$link_node->appendChild( $xml->createCDATASection( site_url() ) );
		//Add description node
		$title_node = $xml->createElement( 'description' );
		$root->appendChild( $title_node );
		$project_desc = isset( $project_desc ) ? html_entity_decode( strip_tags( $project_desc ) ) : '';

		$title_node->appendChild( $xml->createCDATASection( $project_desc ) );
		// Add child nodes
		$multiple_attr_keys = array( 'shipping', 'tax', 'subscription_cost', 'product_detail' );
		
		foreach ( $data as $key => $val ) {
			$entry = $xml->createElement( 'item' );
			$root->appendChild( $entry );
			foreach ( $val as $field_name => $field_value ) {
				$field_name = $field_name; // preg_replace has the allowed characters
				$name       = $entry->appendChild( $xml->createElement( 'g:' . $field_name ) );
				if ( in_array( $field_name, $multiple_attr_keys ) ) {
					$multi_attr_values = explode( ':', $field_value );
					if ( count( $multi_attr_values ) ) {
						$multilevel_attributes = $this->elex_fpf_get_multilevel_attributes();
						foreach ( $multi_attr_values as $index => $value_to_be_mapped ) {
							if ( $value_to_be_mapped ) {

					
								$multi_level        = $name->appendChild( $xml->createElement( 'g:' . $multilevel_attributes[ $field_name ][ $index ] ) );
								$value_to_be_mapped = isset( $value_to_be_mapped ) ? html_entity_decode( strip_tags( $value_to_be_mapped ) ) : '';

								$multi_level->appendChild( $xml->createCDATASection( $value_to_be_mapped ) );
							}
						}
					}
				} else {
					$field_value = isset( $field_value ) ? html_entity_decode( strip_tags( $field_value ) ) : '';

					$name->appendChild( $xml->createCDATASection( $field_value ) );
				
				}
			}
		}
		// Set the formatOutput attribute of xml to true
		$xml->formatOutput = true;
		// Save as file
		$xml->save( $path . '.xml' ); // save as fil
	}

	public function elex_dhl_return_wpml_string( $string_to_translate, $name, $language ) {
		/**
		 * Registers a single translatable string with WPML.
		 *
		 * This action registers the string with WPML for translation. It is useful for dynamic strings that need to be translated.
		 *
		 * @since 1.0.0
		 * @param string $context The context for the string. Helps to group similar strings together.
		 * @param string $name The name or key for the string being registered.
		 * @param string $string_to_translate The actual string that needs to be translated.
		 */
		do_action( 'wpml_register_single_string', 'elex-product-feed', $name, $string_to_translate );
		 /**
		 * Filters a single string for translation using WPML.
		 *
		 * This filter is applied to translate a specific string into the desired language.
		  *
		 * @since 1.0.0
		 * 
		 * @param string $string_to_translate The string to be translated.
		 * @param string $context The context for the string. Helps to group similar strings together.
		 * @param string $name The name or key for the string being translated.
		 * @param string $language The target language for translation.
		 * 
		 * @return string The translated string.
		 */
		$ret_string = apply_filters( 'wpml_translate_single_string', $string_to_translate, 'elex-product-feed', $name, $language );
		return $ret_string;
	}
	public function elex_fpf_get_multilevel_attributes() {
		return array(
			'shipping'          => array(
				'country', 
				'region',
				'service',
				'price',
			),
			'tax'               => array(
				'country',
				'region',
				'rate',
				'tax_ship',
			),
			'subscription_cost' => array(
				'period',
				'period_length',
				'amount',
			),
			'product_detail'    => array(
				'section_name',
				'attribute_name',
				'attribute_value',
			),
		);
	}


	public function elex_fpf_join_files( array $files, $result, $file_mime_type ) {
		$delimeter = ',';
		if ( '.tsv' === $file_mime_type ) {
			$delimeter = "\t";
		}
		$wh = fopen( $result, 'w+' );
		$i  = 0;
		foreach ( $files as $file_path ) {
			$file = fopen( $file_path, 'r' );
			if ( 0 !== $i ) {
				$data = array();
				while ( ( $line = fgetcsv( $file, 0, $delimeter ) ) !== false ) {
					// Store every line in an array
					$data[] = $line;
				}
				fclose( $file );

				// Remove the first element from the stored array / first line of file being read
				array_shift( $data );

				// Open file for writing
				$file = fopen( $file_path, 'w' );

				// Write remaining lines to file
				foreach ( $data as $fields ) {
					fputcsv( $file, $fields, $delimeter );
				}
				fclose( $file );
			}
			$i++;
			$fh = fopen( $file_path, 'r' );
			while ( ! feof( $fh ) ) {
				fwrite( $wh, fgets( $fh ) );
			}
			fclose( $fh );
			unset( $fh );
			//usually last line doesn't have a newline
		}
		fclose( $wh );
		unset( $wh );
	}

	public function elex_get_tax_and_ship_details_csv( $shipping_data, $tax_data, $product_detail_data, $subscription_cost_data, $csv, $seperated_value, $currency_code ) {
		
	

		if ( ! empty( $shipping_data ) ) {
			$ship_keys  = array_keys( $shipping_data );
			$value_ship = '';
			if ( in_array( 'country', $ship_keys ) ) {
				$value_ship .= $shipping_data['country'] . ':' ;
			} else {
				$value_ship .= ':' ;
			}
			if ( in_array( 'region', $ship_keys ) ) {
				$value_ship .= $shipping_data['region'] . ':' ;
			} else {
				$value_ship .= ':' ;
			}
			if ( in_array( 'service', $ship_keys ) ) {
				$value_ship .= $shipping_data['service'] . ':'  ;
			} else {
				$value_ship .= ':' ;
			}
			if ( in_array( 'price', $ship_keys ) ) {
				$value_ship .= $shipping_data['price'] . ' ' . $currency_code  ;
			}
			
			$csv[] = $value_ship;
		}
		if ( ! empty( $tax_data ) ) {
			$tax_keys  = array_keys( $tax_data );
			$tax_value = '';
			if ( in_array( 'country', $tax_keys ) ) {
				$tax_value .= $tax_data['country'] ;
			} else {
				$tax_value .= ':' ;
			}
			if ( in_array( 'region', $tax_keys ) ) {
				$tax_value .= $tax_data['region'] ;
			} else {
				$tax_value .= ':' ;
			}
			if ( in_array( 'rate', $tax_keys ) ) {
				$tax_value .= $tax_data['rate'] ;
			} else {
				$tax_value .= ':' ;
			}
			if ( in_array( 'tax_ship', $tax_keys ) ) {
				$tax_value .= $tax_data['tax_ship'] ;
			}
			$csv[] = $tax_value;
			
		}
		if ( ! empty( $product_detail_data ) ) {
			$product_detail_keys = array_keys( $product_detail_data );
			$prod_value          = '';
			if ( in_array( 'section_name', $product_detail_keys ) ) {
				$prod_value .= $product_detail_data['section_name'] ;
			} else {
				$prod_value .= ':' ;
			}
			if ( in_array( 'attribute_name', $product_detail_keys ) ) {
				$prod_value .= $product_detail_data['attribute_name'] ;
			} else {
				$prod_value .= ':' ;
			}
			if ( in_array( 'attribute_value', $product_detail_keys ) ) {
				$prod_value .= $product_detail_data['attribute_value'] ;
			} 
			$csv[] = $prod_value;

		}
		if ( ! empty( $subscription_cost_data ) ) {
			$subscription_cost_keys = array_keys( $subscription_cost_data );
			$subs_val               = '';
			if ( in_array( 'period', $subscription_cost_keys ) ) {
				$subs_val .= $subscription_cost_data['period'] ;
			} else {
				$subs_val .= ':' ;
			}
			if ( in_array( 'period_length', $subscription_cost_keys ) ) {
				$subs_val .= $subscription_cost_data['period_length'] ;
			} else {
				$subs_val .= ':' ;
			}
			if ( in_array( 'amount', $subscription_cost_keys ) ) {
				$subs_val .= $subscription_cost_data['amount'] ;
			} 
			$csv[] = $subs_val;

		}
		return $csv;
	}

	public function elex_fpf_get_value_from_condition_simple( $conditions, $google_attr, $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, $add_items, $currency_conversion, $sale_country ) {
		$success      = false;
		$map_attr_val = '';
		foreach ( $conditions as  $condition ) {
			foreach ( $condition[0] as $value ) {
				if ( $value[0] && $value[2] ) {
					
					$attr_val = $this->elex_fpf_get_simple_product_attr_values( $value[0], $google_attr, $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, $add_items, $currency_conversion, $sale_country );
					if ( $attr_val ) {
						$check_cond = $this->elex_fpf_check_condition( $attr_val, $value[1], $value[2] );
						$success    = $check_cond;
						if ( $check_cond && 'OR' === $condition[1] ) {
							$success = true;
							break;
						} elseif ( ! $check_cond && 'AND' === $condition[1] ) {
							$success = false;
							break;
						}
					}
				}
			}
			if ( $success ) {
				if ( $condition[2] ) { 
					if ( ( strpos( $condition[2], 'elex_text_val', 0 ) === 0 ) ) {
						$map_attr_val = str_replace( 'elex_text_val', '', $condition[2] );
					} else {
						
						$map_attr_val = $this->elex_fpf_get_simple_product_attr_values( $condition[2], $google_attr, $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, $add_items, $currency_conversion, $sale_country );
					}
				}
				if ( isset( $condition[3] ) && is_array( $condition[3] ) ) {
					$prepend_value = '';
					foreach ( $condition[3] as $value ) {
						if ( $value[0] ) {
							
							$value_to_prepend = $this->elex_fpf_get_simple_product_attr_values( $value[0], $google_attr, $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, $add_items, $currency_conversion, $sale_country );

							if ( $value_to_prepend ) {
								   $prepend_value .= $this->elex_fpf_prepend_append_value( $value_to_prepend, $value[1], 'prepend' );
							}
						}
					}
					$map_attr_val = $prepend_value . ' ' . $map_attr_val;
				}
				if ( isset( $condition[4] ) && is_array( $condition[4] ) ) {
					$append_value = '';
					foreach ( $condition[4] as $value ) {
						if ( $value[0] ) {
						
							   $value_to_append = $this->elex_fpf_get_simple_product_attr_values( $value[0], $google_attr, $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, $add_items, $currency_conversion, $sale_country );

							if ( $value_to_append ) {
								$append_value .= $this->elex_fpf_prepend_append_value( $value_to_append, $value[1], 'append' );
							}
						}
					}
					$map_attr_val .= ' ' . $append_value;
				}

				break;
			}
		}
		return $map_attr_val;
	}

	public function elex_fpf_get_value_from_condition_variable( $conditions, $google_attr, $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, $add_items, $currency_conversion, $sale_country ) {
		$success      = false;
		$map_attr_val = '';
		foreach ( $conditions as  $condition ) {
			foreach ( $condition[0] as $value ) {
				if ( $value[0] && $value[2] ) {
					
					$attr_val = $this->get_vari_product_attribute_value( $value[0], $google_attr, $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, $add_items, $currency_conversion, $sale_country );
					if ( $attr_val ) {
						$check_cond = $this->elex_fpf_check_condition( $attr_val, $value[1], $value[2] );
						$success    = $check_cond;
						if ( $check_cond && 'OR' === $condition[1] ) {
							$success = true;
							break;
						} elseif ( ! $check_cond && 'AND' === $condition[1] ) {
							$success = false;
							break;
						}
					}
				}
			}
			if ( $success ) {
				if ( $condition[2] ) {
					if ( ( strpos( $condition[2], 'elex_text_val', 0 ) === 0 ) ) {
						$map_attr_val = str_replace( 'elex_text_val', '', $condition[2] );
					} else {
						
						$map_attr_val = $this->get_vari_product_attribute_value( $condition[2], $google_attr, $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, $add_items, $currency_conversion, $sale_country );
					}
				}
				if ( isset( $condition[3] ) && is_array( $condition[3] ) ) {
					$prepend_value = '';
					foreach ( $condition[3] as $value ) {
						if ( $value[0] ) {
							
							$value_to_prepend = $this->get_vari_product_attribute_value( $value[0], $google_attr, $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, $add_items, $currency_conversion, $sale_country );

							if ( $value_to_prepend ) {
								   $prepend_value .= $this->elex_fpf_prepend_append_value( $value_to_prepend, $value[1], 'prepend' );
							}
						}
					}
					$map_attr_val = $prepend_value . ' ' . $map_attr_val;
				}
				if ( isset( $condition[4] ) && is_array( $condition[4] ) ) {
					$append_value = '';
					foreach ( $condition[4] as $value ) {
						if ( $value[0] ) {
		
							   $value_to_append = $this->get_vari_product_attribute_value( $value[0], $google_attr, $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, $add_items, $currency_conversion, $sale_country );

							if ( $value_to_append ) {
								$append_value .= $this->elex_fpf_prepend_append_value( $value_to_append, $value[1], 'append' );
							}
						}
					}
					$map_attr_val .= ' ' . $append_value;
				}

				break;
			}
		}
		return $map_attr_val;
	}

	public function elex_fpf_check_condition( $attr_val, $condition_param, $compare_with ) {
		$check_cond = false;
		switch ( $condition_param ) {
			case 'contains':
				if ( strpos( $attr_val, $compare_with ) !== false ) {
					 $check_cond = true;
				}
				break;
			case 'string_equals':
				if ( $attr_val === $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'starts_with':
				if ( substr( $attr_val, 0, strlen( $compare_with ) ) === $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'ends_with':
				if ( substr( $attr_val, -strlen( $compare_with ) ) === $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'less_than':
				if ( $attr_val < $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'less_than_equal':
				if ( $attr_val <= $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'greater_than':
				if ( $attr_val > $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'greater_than_equal':
				if ( $attr_val >= $compare_with ) {
					$check_cond = true;
				}
				break;
			case 'arith_equals':
				if ( $attr_val === $compare_with ) {
					$check_cond = true;
				}
				break;
			default:
				$check_cond = false;
				break;
		}
		return $check_cond;
	}

	public function elex_fpf_prepend_append_value( $attr_val, $delimeter, $action ) {
		$add_delimeter = '';
		switch ( $delimeter ) {
			case 'space':
				$add_delimeter .= ' ';
				break;
			case 'comma':
				$add_delimeter .= ',';
				break;
			case 'dot':
				$add_delimeter .= '.';
				break;
			case 'less_than':
				$add_delimeter .= '<';
				break;
			case 'greater_than':
				$add_delimeter .= '>';
				break;
			case 'equals':
				$add_delimeter .= '=';
				break;
			case 'double_equals':
				$add_delimeter .= '==';
				break;
			case 'semicolon':
				$add_delimeter .= ';';
				break;
			case 'pipe':
				$add_delimeter .= '|';
				break;
			case 'backslash':
				$add_delimeter .= '\\';
				break;
			case 'forward_slash':
				$add_delimeter .= '/';
				break;
			default:
				$add_delimeter .= '';
				break;
		}
		if ( 'prepend' === $action ) {
			$attr_val .= $add_delimeter;
		} else {
			$attr_val = $add_delimeter . $attr_val;
		}
		return $attr_val;
	}

	public function elex_fpf_check_stock_and_sold_quantity( $product, $stock_check, $stock_quantity, $prod_sold_check, $sold_quantity, $stock_status ) {
		
		$arg_list = func_get_args();
		if ( ( ! $stock_check && ! $prod_sold_check && ! $stock_status ) || ( '' == $stock_quantity && '' == $sold_quantity && empty( $stock_status ) ) ) {
			return true;
		}
		$stock_quatity = $this->check_stock_quantity( $product, $stock_check, $stock_quantity );
		$sold_quatity  = $this->check_sold_quantity( $product, $prod_sold_check, $sold_quantity );
		$stock_status  = $this->check_stock_status( $product, $stock_status );
		return ( $stock_quatity && $sold_quatity ) && $stock_status ;
	
	}

	public function check_sold_quantity( $product, $prod_sold_check, $sold_quantity ) {
		
		if ( empty( $prod_sold_check ) || '' === $sold_quantity ) {
			return true;
		}
		$product_quantity = $product->get_total_sales();
		switch ( $prod_sold_check ) {
			case 'equals':
				if ( $sold_quantity == $product_quantity ) {
					return true;
				}
				break;
			case 'greater_than':
				if ( $product_quantity >= $sold_quantity ) {
					return true;
				}
				break;
			case 'less_than':
				if ( $product_quantity <= $sold_quantity ) {
					return true;
				}
				break;
		}
		return false;
	}
	

	public function check_stock_quantity( $product, $stock_check, $stock_quantity ) {
	
		if ( empty( $stock_check ) || '' === $stock_check ) {
			return true;
		}
		if ( empty( $product->get_manage_stock() && 'instock' === $product->get_stock_status() ) ) {
			if ( 'less_than' === $stock_check && intval( $stock_quantity ) <= 0 ) {
				return false;
			}
			return true;
		}
		if ( ! empty( $product->get_manage_stock() ) ) {
			$product_quantity = $product->get_stock_quantity();

		}

		switch ( $stock_check ) {
			case 'equals':
				if ( $stock_quantity == $product_quantity ) {
					return true;
				}
				break;
			case 'greater_than':
				if ( $product_quantity >= $stock_quantity ) {
					return true;
				}
				break;
			case 'less_than':
				if ( $product_quantity <= $stock_quantity ) {
					return true;
				}
				break;
		}
		return false;


	}
	public function check_stock_status( $product, $stocks ) {
		if ( empty( $stocks ) ) {
			return true;
		}

		if ( ! in_array( $product->get_stock_status(), $stocks ) ) {
			return false;
		}

		return true;
	}




	public function get_vari_product_attribute_value( $prod_attr, $google_attr, $product_attributes, $vari_attributes, $vari_attributes_title, $ids, $variations, $variable_prod, $google_cat, $prefix, $product_details, $variable_product_details, $add_items, $currency_conversion, $sale_country ) {
		//Compatibility with WPML.

	


		$wpml_product   = '';
		$product_parent = wc_get_product( $variations );
		$product        = wc_get_product( $ids );

		if ( is_array( $this->setting_tab_fields ) && isset( $this->setting_tab_fields['wpml_language'] ) && has_filter( 'wpml_object_id' ) ) {
			/**
			 * Filters the product ID to get the translated ID for the specified language.
			 *
			 * This filter is used to retrieve the translated product ID for a given language.
			 *
			 * @since 1.0.0
			 * 
			 * @param int    $object_id       The original product ID.
			 * @param string $object_type     The type of object being translated, in this case, 'product'.
			 * @param bool   $return_original Whether to return the original ID if a translation is not found.
			 * @param string $language_code   The language code for the desired translation (e.g., 'fr' for French).
			 * 
			 * @return int|null The translated product ID, or null if no translation is found.
			 */
			$wpml_product_id      = apply_filters( 'wpml_object_id', $variable_prod->get_id(), 'product', true, $this->setting_tab_fields['wpml_language'] );
			$wpml_product         = wc_get_product( $wpml_product_id );
			$wpml_product_details = $wpml_product->get_data();
		}
	
		$map_prod_attr_val = '';
		$prod_attr_key     = $prod_attr;
		$recom_values      = explode( '_', $prod_attr );
		if ( 'rec' === $recom_values[0] ) {
			$map_prod_attr_val = $recom_values[1];
		} elseif ( ( strpos( $prod_attr, 'elex_text_val', 0 ) === 0 ) ) {
			$map_prod_attr_val = str_replace( 'elex_text_val', '', $prod_attr );
		} elseif ( isset( $product_attributes[ $prod_attr_key ] ) && 'meta' === $product_attributes[ $prod_attr_key ]['type'] ) {
			$map_prod_attr_val = $product_parent->get_meta( $prod_attr );
			if ( '_sku' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_tax_class' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'standard';
			}
			if ( '_elex_fpf_gtin' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_gtin' === $prod_attr ) {
				$map_prod_attr_val = str_replace( '-', '', $map_prod_attr_val );
				$map_prod_attr_val = str_replace( ' ', '', $map_prod_attr_val );

			}
			if ( '_elex_fpf_importer_name' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_street1' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_street2' === $prod_attr && '' === $map_prod_attr_val ) {
				   $map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_city' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_region' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_postal_code' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_country' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_origin_country' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}

			if ( '_elex_fpf_manufacturer_name' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}   
			if ( '_elex_fpf_manufacturer_address' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
		
			if ( '_elex_fpf_size_usa' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}   
			if ( '_elex_fpf_sell_usa' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			
			if ( '_elex_fpf_mpn' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_brand' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
		} elseif ( 'ID' === $prod_attr ) {
			$map_prod_attr_val = $variations;
		} elseif ( 'prod_category' === $prod_attr ) {
			$term_list = wp_get_post_terms( $ids, 'product_cat', array( 'fields' => 'ids' ) );
			$cid       = end( $term_list );
			$term      = get_term_by( 'id', $cid, 'product_cat' );
			if ( $term ) {
				$map_prod_attr_val = $term->name;
			}
		} elseif ( '_stock_status' === $prod_attr ) {
			$map_prod_attr_val = $product_parent->get_stock_status();
			if ( 'instock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'in stock';
			}
			if ( 'outofstock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'out of stock';
			}
			if ( 'onbackorder' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'preorder';
			}
		} elseif ( 'post_title' === $prod_attr ) {
			if ( $wpml_product ) {
				$vari_title = $wpml_product->get_title();
			} else {
				$vari_title = $variable_prod->get_title();
			}
			foreach ( $vari_attributes_title as $attr_key => $attr_val ) {
				$attr_arr = explode( ':', $attr_val );
				if ( isset( $attr_arr[1] ) ) {
					$vari_title .= '/' . trim( $attr_arr[1] );
				}
			}
			$map_prod_attr_val = $vari_title;
		} elseif ( 'post_content' === $prod_attr ) {
			$variations_desc   = '';
			$map_prod_attr_val = $product_parent->get_meta( '_elex_fpf_prod_desc' );
			if ( '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '' === $map_prod_attr_val ) {
				if ( $wpml_product ) {
					$variations_desc = $wpml_product_details['description'] ? html_entity_decode( strip_tags( $wpml_product_details['description'] ) ) : '';
					if ( '' === trim( $variations_desc ) ) {
						$variations_desc = $wpml_product->get_description() ? html_entity_decode( strip_tags( $wpml_product->get_description() ) ) : '';
					}
				} else {
					$variations_desc = $variable_product_details['description'] ? html_entity_decode( strip_tags( $variable_product_details['description'] ) ) : '';
					if ( '' === trim( $variations_desc ) ) {
						$variations_desc = $product_details['description'] ? html_entity_decode( strip_tags( $product_details['description'] ) ) : '';
					}
				}
			}
			if ( '' !== $variations_desc ) {
				$variations_desc   = str_replace( "\r\n", '', $variations_desc );
				$map_prod_attr_val = $variations_desc;
			}       
		} elseif ( 'post_excerpt' === $prod_attr ) {
			if ( $wpml_product ) {
				$map_prod_attr_val = $wpml_product->get_short_description() ? html_entity_decode( strip_tags( $wpml_product->get_short_description() ) ) : '';
			} else {
				$map_prod_attr_val = $product_details['short_description'] ? html_entity_decode( strip_tags( $product_details['short_description'] ) ) : '';
			}
		} elseif ( 'price' === $prod_attr ) {
			$map_prod_attr_val = $product_parent->get_meta( '_elex_fpf_prod_desc' );
			if ( '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( '_elex_fpf_prod_desc' );
				if ( '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $variable_prod->get_price();
				}
			}
			if ( is_numeric( $currency_conversion ) && is_numeric( $map_prod_attr_val ) ) {
				$map_prod_attr_val *= $currency_conversion;
			}
			if ( is_numeric( $map_prod_attr_val ) ) {
				$map_prod_attr_val = round( $map_prod_attr_val, 2 );
			}       
		} elseif ( 'price_incl_tax' === $prod_attr ) {
			$map_prod_attr_val = elex_fpf_get_tax_rate_for_country( $sale_country, $variable_prod->get_price() );
			if ( is_numeric( $currency_conversion ) && is_numeric( $map_prod_attr_val ) ) {
				$map_prod_attr_val *= $currency_conversion;
			}
		} elseif ( 'post_author' === $prod_attr ) {
			$author_id         = get_post_field( 'post_author', $ids );
			$map_prod_attr_val = get_the_author_meta( 'user_nicename', $author_id );
		} elseif ( 'permalink' === $prod_attr ) {
			$vari_link = get_permalink( $ids );
			$temp      = 0;
			foreach ( $vari_attributes as $attr_key => $attr_val ) {
				if ( $temp ) {
					$vari_link .= '&';
				} else {
					$vari_link .= '?';
				}
				$vari_link .= 'attribute_' . rawurlencode( $attr_key ) . '=' . rawurlencode( $attr_val );
				$temp++;
			}
			$map_prod_attr_val = $vari_link;
		} elseif ( 'google_category' === $prod_attr ) {
			$map_prod_attr_val = $google_cat;
		} elseif ( 'item_group_id' === $prod_attr ) {
			$map_prod_attr_val = $ids;
		} elseif ( 'wc_currency' === $prod_attr ) {
			$map_prod_attr_val = get_woocommerce_currency();
		} elseif ( 'product_type' === $prod_attr ) {
			$map_prod_attr_val = 'variation';
		} elseif ( 'main_image' === $prod_attr ) {
			$map_prod_attr_val = $product_parent->get_meta( '_elex_fpf_image_link' );
			if ( '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( '_elex_fpf_image_link' );
			}
			if ( '' === $map_prod_attr_val ) {
				$image_details = wp_get_attachment_image_src( get_post_thumbnail_id( $variations ), 'single-post-thumbnail' );
				if ( ! $image_details ) {
					$image_details = wp_get_attachment_image_src( get_post_thumbnail_id( $ids ), 'single-post-thumbnail' );
				}
				if ( $image_details ) {
					$map_prod_attr_val = $image_details[0];
				}
			}
		} elseif ( 'gallery_images' === $prod_attr ) {
			$product_image_link       = '';
				$fpf_selected_product = wc_get_product( $variations );
				$attachment_ids       = $fpf_selected_product->get_gallery_image_ids();
			foreach ( $attachment_ids as $attachment_id ) {
				$product_image_link .= wp_get_attachment_url( $attachment_id ) . ';';
			}
			// $image_details = wp_get_attachment_image_src( get_post_thumbnail_id( $variations ), 'single-post-thumbnail' );
			if ( ! $product_image_link ) {
				$product_image_link   = '';
				$fpf_selected_product = wc_get_product( $ids );
				$attachment_ids       = $fpf_selected_product->get_gallery_image_ids();
				foreach ( $attachment_ids as $attachment_id ) {
					substr( sanitize_text_field( $product_image_link ), 0, -1 );
					$product_image_link .= wp_get_attachment_url( $attachment_id ) . ';';
				}
				// $image_details = wp_get_attachment_image_src( get_post_thumbnail_id( $ids ), 'single-post-thumbnail' );
			}
			if ( $product_image_link ) {
				$map_prod_attr_val = substr( sanitize_text_field( $product_image_link ), 0, -1 );
			}       
		} elseif ( 'product_tags' === $prod_attr ) {
			$terms = get_the_terms( $ids, 'product_tag' );
			if ( $terms ) {
				$map_prod_attr_val = $terms[0]->name;
			}
		} elseif ( 'review_comment' === $prod_attr ) {
			$args     = array(
				'post_type' => 'product',
				'post_id'   => $ids,
			);
			$comments = get_comments( $args );
			if ( $comments ) {
				$map_prod_attr_val = $comments[0]->comment_content;
			}
		} elseif ( 'review_count' === $prod_attr ) {
			$map_prod_attr_val = $product->get_meta( '_wc_average_rating' );
		}
		if ( '_stock_status' === $prod_attr ) {
			$map_prod_attr_val = $product_parent->get_stock_status();
			if ( 'instock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'in stock';
			}
			if ( 'outofstock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'out of stock';
			}
			if ( 'onbackorder' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'preorder';
			}       
		}   



		return $map_prod_attr_val;
	}

	public function elex_fpf_get_simple_product_attr_values( $prod_attr, $google_attr, $ids, $product, $product_details, $prefix, $google_cat, $product_attributes, $add_items, $currency_conversion, $sale_country ) {
		//Compatibility with WPML.

		$wpml_product = '';
		if ( is_array( $this->setting_tab_fields ) && isset( $this->setting_tab_fields['wpml_language'] ) && has_filter( 'wpml_object_id' ) ) {
			/**
			 * Filters the product ID to get the translated ID for the specified language using WPML.
			 *
			 * This filter retrieves the translated product ID for a given language, allowing WPML to return the correct ID based on the specified language.
			 *
			 * @since 1.0.0
			 *
			 * @param int    $object_id       The original product ID.
			 * @param string $object_type     The type of object being translated, here it is 'product'.
			 * @param bool   $return_original Whether to return the original ID if a translation is not found.
			 * @param string $language_code   The language code for the desired translation, e.g., 'fr' for French.
			 * 
			 * @return int|null The translated product ID, or null if no translation is found.
			 */
			$wpml_product_id      = apply_filters( 'wpml_object_id', $product->get_id(), 'product', true, $this->setting_tab_fields['wpml_language'] );
			$wpml_product         = wc_get_product( $wpml_product_id );
			$wpml_product_details = $wpml_product->get_data();
		}
		$product           = wc_get_product( $ids );
		$map_prod_attr_val = '';
		$prod_attr_key     = $prod_attr;
		$recom_values      = explode( '_', $prod_attr );
		if ( 'rec' === $recom_values[0] ) {
			$map_prod_attr_val = $recom_values[1];
		} elseif ( ( strpos( $prod_attr, 'elex_text_val', 0 ) === 0 ) ) {
			$map_prod_attr_val = str_replace( 'elex_text_val', '', $prod_attr );
		} elseif ( isset( $product_attributes[ $prod_attr_key ] ) && 'meta' === $product_attributes[ $prod_attr_key ]['type'] ) {
			$map_prod_attr_val = $product->get_meta( $prod_attr );  
			if ( '_tax_class' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'standard';
			}
		} elseif ( isset( $product_attributes[ $prod_attr_key ] ) && 'meta' === $product_attributes[ $prod_attr_key ]['type'] ) {
			$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			
			if ( '_sku' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			}
			if ( '_tax_class' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'standard';
			}
			if ( '_elex_fpf_gtin' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			}
			
			if ( '_elex_fpf_importer_name' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr );

			}


			if ( '_elex_fpf_importer_street1' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_street2' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			}
			if ( '_elex_fpf_importer_city' === $prod_attr && '' === $map_prod_attr_val ) {
					$$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			}
			if ( '_elex_fpf_importer_region' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			}
			if ( '_elex_fpf_importer_postal_code' === $prod_attr && '' === $map_prod_attr_val ) {
					$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_importer_country' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr ); 
			}
			if ( '_elex_fpf_origin_country' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_manufacturer_name' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}   
			if ( '_elex_fpf_manufacturer_address' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
		
			if ( '_elex_fpf_size_usa' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}   
			if ( '_elex_fpf_sell_usa' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			
			if ( '_elex_fpf_mpn' === $prod_attr && '' === $map_prod_attr_val ) {
				$$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
			if ( '_elex_fpf_brand' === $prod_attr && '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_meta( $prod_attr );
			}
		} elseif ( 'ID' === $prod_attr ) {
			$map_prod_attr_val = $ids;
		} elseif ( 'prod_category' === $prod_attr ) {
			$term_list = wp_get_post_terms( $ids, 'product_cat', array( 'fields' => 'ids' ) );
			$cid       = end( $term_list );
			$term      = get_term_by( 'id', $cid, 'product_cat' );
			if ( $term ) {
				$map_prod_attr_val = $term->name;
			}
		} elseif ( '_stock_status' === $prod_attr ) {
			$map_prod_attr_val = $product->get_stock_status(); 
			if ( 'instock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'in stock';
			}
			if ( 'outofstock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'out of stock';
			}
			if ( 'onbackorder' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'preorder';
			}       
		} elseif ( 'post_title' === $prod_attr ) {
			if ( $wpml_product ) {
				$map_prod_attr_val = $wpml_product->get_name();
			} else {
				$map_prod_attr_val = $product->get_name();
			}
		} elseif ( 'post_content' === $prod_attr ) {
			$map_prod_attr_val = $product->get_meta( '_elex_fpf_prod_desc' );
			if ( '' === $map_prod_attr_val ) {
				if ( $wpml_product ) {
					$map_prod_attr_val = $wpml_product_details['description'] ? html_entity_decode( strip_tags( $wpml_product_details['description'] ) ) : '';
				} else {
					$map_prod_attr_val = $product_details['description'] ? html_entity_decode( strip_tags( $product_details['description'] ) ) : '';
				}
			}
		} elseif ( 'post_excerpt' === $prod_attr ) {
			if ( $wpml_product ) {
				$map_prod_attr_val = $wpml_product_details['short_description'] ? html_entity_decode( strip_tags( $wpml_product_details['short_description'] ) ) : '';
			} else {
				$map_prod_attr_val = $product_details['short_description'] ? html_entity_decode( strip_tags( $product_details['short_description'] ) ) : '';
			}
		} elseif ( 'price' === $prod_attr ) {
			$map_prod_attr_val = $product->get_meta( '_elex_fpf_price' ); 
			if ( '' === $map_prod_attr_val ) {
				$map_prod_attr_val = $product->get_price();
			}
			if ( is_numeric( $currency_conversion ) && is_numeric( $map_prod_attr_val ) ) {
				$map_prod_attr_val *= $currency_conversion;
			}
			if ( is_numeric( $map_prod_attr_val ) ) {
				$map_prod_attr_val = round( $map_prod_attr_val, 2 );
			}
		} elseif ( 'price_incl_tax' === $prod_attr ) {
			$map_prod_attr_val = elex_fpf_get_tax_rate_for_country( $sale_country, $product->get_price() );
			if ( is_numeric( $currency_conversion ) && is_numeric( $map_prod_attr_val ) ) {
				$map_prod_attr_val *= $currency_conversion;
			}
		} elseif ( 'attachment_url' === $prod_attr ) {
			$map_prod_attr_val = wp_get_attachment_url( get_post_thumbnail_id( $ids ) );
		} elseif ( 'menu_order' === $prod_attr ) {
			$map_prod_attr_val = get_post_field( 'menu_order', $ids );
		} elseif ( 'post_author' === $prod_attr ) {
			$author_id         = get_post_field( 'post_author', $ids );
			$map_prod_attr_val = get_the_author_meta( 'user_nicename', $author_id );
		} elseif ( 'post_date' === $prod_attr ) {
			$time              = get_the_time( '', $ids );
			$map_prod_attr_val = get_the_date( '', $ids ) . ' ' . $time;
		} elseif ( 'post_date_gmt' === $prod_attr ) {
			$time              = get_post_time( '', $ids, true );
			$map_prod_attr_val = get_the_date( '', $ids );
		} elseif ( 'post_modified' === $prod_attr ) {
			$time              = get_the_modified_time( '', $ids );
			$map_prod_attr_val = get_the_modified_date( '', $ids ) . ' ' . $time;
		} elseif ( 'post_modified_gmt' === $prod_attr ) {
			$map_prod_attr_val = get_the_modified_date( '', $ids );
		} elseif ( 'permalink' === $prod_attr ) {
			$map_prod_attr_val = get_permalink( $ids );
		} elseif ( 'google_category' === $prod_attr ) {
			$map_prod_attr_val = $google_cat;
		} elseif ( 'main_image' === $prod_attr ) {
			$map_prod_attr_val = $product->get_meta( '_elex_fpf_image_link' );
			if ( '' === $map_prod_attr_val ) {
				$image_details = wp_get_attachment_image_src( get_post_thumbnail_id( $ids ), 'single-post-thumbnail' );
				if ( $image_details ) {
					$map_prod_attr_val = $image_details[0];
				}
			}
		} elseif ( 'gallery_images' === $prod_attr ) {
				$product_image_link   = '';
				$fpf_selected_product = wc_get_product( $ids );
				$attachment_ids       = $fpf_selected_product->get_gallery_image_ids();
			foreach ( $attachment_ids as $attachment_id ) {
				substr( sanitize_text_field( $product_image_link ), 0, -1 );
				$product_image_link .= wp_get_attachment_url( $attachment_id ) . ';';
			}
			if ( $product_image_link ) {
				$map_prod_attr_val = substr( sanitize_text_field( $product_image_link ), 0, -1 );
			}       
		} elseif ( 'item_group_id' === $prod_attr ) {
			$map_prod_attr_val = '';
		} elseif ( 'wc_currency' === $prod_attr ) {
			$map_prod_attr_val = get_woocommerce_currency();
		} elseif ( 'product_type' === $prod_attr ) {
			$map_prod_attr_val = 'simple';
		} elseif ( 'product_tags' === $prod_attr ) {
			$terms = get_the_terms( $ids, 'product_tag' );
			if ( $terms ) {
				$map_prod_attr_val = $terms[0]->name;
			}
		} elseif ( 'review_comment' === $prod_attr ) {
			$args     = array(
				'post_type' => 'product',
				'post_id'   => $ids,
			);
			$comments = get_comments( $args );
			if ( $comments ) {
				$map_prod_attr_val = $comments[0]->comment_content;
			}
		} elseif ( 'review_count' === $prod_attr ) {
			$map_prod_attr_val = $product->get_meta( '_wc_average_rating' );
		}
		if ( '_stock_status' === $prod_attr ) {
			$map_prod_attr_val = $product->get_stock_status();
			if ( 'instock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'in stock';
			}
			if ( 'outofstock' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'out of stock';
			}
			if ( 'onbackorder' === $map_prod_attr_val ) {
				$map_prod_attr_val = 'preorder';
			}
		}   
		
		if ( '_elex_fpf_gtin' === $prod_attr ) {
			$map_prod_attr_val = str_replace( '-', '', $map_prod_attr_val );
			$map_prod_attr_val = str_replace( ' ', '', $map_prod_attr_val );
			
		}   
		if ( '_stock' === $prod_attr ) {
			$map_prod_attr_val = $product->get_stock_quantity();
		}
		return $map_prod_attr_val;
	}

	public function elex_fpf_mapping_settings_field() {
		check_ajax_referer( 'ajax-elex-fpf-nonce', '_ajax_elex_fpf_nonce' );
		$google_cats       = ( isset( $_POST['google_cats'] ) && ! empty( $_POST['google_cats'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['google_cats'] ) ) : '';
		$country_sale      = isset( $_POST['country_of_sale'] ) ? sanitize_text_field( $_POST['country_of_sale'] ) : '';
		$include_variation = isset( $_POST['include_variation'] ) ? sanitize_text_field( $_POST['include_variation'] ) : '';
		$us_country_check  = isset( $_POST['us_country_check'] ) ? sanitize_text_field( $_POST['us_country_check'] ) : '';
		$mapping_attr      = $this->elex_fpf_get_mapping_attr( $us_country_check, $google_cats, $country_sale, $include_variation );
		die( wp_json_encode( $mapping_attr ) );
	}

	public function elex_fpf_get_mapping_attr( $us_country_check, $google_cats, $country, $include_variation, $saved_google_attr = array() ) {
		$google_attr          = $this->elex_fpf_get_google_attributes();
		$required_attr        = array();
		$required_attr_always = array();
		if ( 'US' === $country ) {
			$google_attr_us = $this->elex_fpf_get_google_attributes_us();
			$google_attr    = array_merge( $google_attr, $google_attr_us );
		}
		if ( 'IN' === $country ) {
			$google_attr_in = $this->elex_fpf_get_google_attributes_in();
			$google_attr    = array_merge( $google_attr, $google_attr_in );
		}
		$required_attr_always ['id']                      = $google_attr['Basic product data']['id'];
		$required_attr_always ['title']                   = $google_attr['Basic product data']['title'];
		$required_attr_always ['description']             = $google_attr['Basic product data']['description'];
		$required_attr_always ['link']                    = $google_attr['Basic product data']['link'];
		$required_attr_always ['image_link']              = $google_attr['Basic product data']['image_link'];
		$required_attr_always ['availability']            = $google_attr['Price & availability']['availability'];
		$required_attr_always ['price']                   = $google_attr['Price & availability']['price'];
		$required_attr_always ['condition']               = $google_attr['Detailed product description']['condition'];
		$required_attr_always ['google_product_category'] = $google_attr['Product category']['google_product_category'];
		$required_attr_always ['brand']                   = $google_attr['Product identifiers']['brand'];
		$required_attr_always ['gtin']                    = $google_attr['Product identifiers']['gtin'];
		$required_attr_always ['mpn']                     = $google_attr['Product identifiers']['mpn'];
		unset( $google_attr['Basic product data']['id'] );
		unset( $google_attr['Basic product data']['title'] );
		unset( $google_attr['Basic product data']['description'] );
		unset( $google_attr['Basic product data']['link'] );
		unset( $google_attr['Basic product data']['image_link'] );
		unset( $google_attr['Price & availability']['availability'] );
		unset( $google_attr['Price & availability']['price'] );
		unset( $google_attr['Product identifiers']['brand'] );
		unset( $google_attr['Product identifiers']['gtin'] );
		unset( $google_attr['Product identifiers']['mpn'] );
		unset( $google_attr['Detailed product description']['condition'] );
		unset( $google_attr['Product category']['google_product_category'] );
		
		if ( 'IN' === $country ) { 
			$required_attr_always ['origin_country']            = $google_attr['Sell in India']['origin_country'];
			$required_attr_always ['importer_name']             = $google_attr['Sell in India']['importer_name'];
			$required_attr_always ['importer_addr_street1']     = $google_attr['Sell in India']['importer_addr_street1'];
			$required_attr_always ['importer_addr_street2']     = $google_attr['Sell in India']['importer_addr_street2'];
			$required_attr_always ['importer_addr_city']        = $google_attr['Sell in India']['importer_addr_city'];
			$required_attr_always ['importer_addr_region']      = $google_attr['Sell in India']['importer_addr_region'];
			$required_attr_always ['importer_addr_postal_code'] = $google_attr['Sell in India']['importer_addr_postal_code'];
			$required_attr_always ['importer_addr_country']     = $google_attr['Sell in India']['importer_addr_country'];

			$required_attr_always ['manufacturer_name']    = $google_attr['Sell in India']['manufacturer_name'];
			$required_attr_always ['manufacturer_address'] = $google_attr['Sell in India']['manufacturer_address'];

		}
		if ( 'US' === $country && 'true' === $us_country_check ) {
			$required_attr_always ['quantity_to_sell_on_facebook'] = $google_attr['Sell in USA']['quantity_to_sell_on_facebook'];
			$required_attr_always ['size']                         = $google_attr['Sell in USA']['size'];
			unset( $google_attr['Detailed product description']['size'] );
		}

		if ( 'true' === $include_variation ) {
			$required_attr_always ['item_group_id'] = $google_attr['Detailed product description']['item_group_id'];
		}
	
		$language_number   = 0;
		$settingd_tab_data = get_option( 'elex_fpf_settings_tab_fields_data' );
		if ( ! is_array( $settingd_tab_data ) || ! isset( $settingd_tab_data['cat_language'] ) ) {
			$language_number = 0; //english
		} else {
			if ( 'en' === $settingd_tab_data['cat_language'] ) {
				$language_number = 0; //english
			} elseif ( 'de' === $settingd_tab_data['cat_language'] ) {
				$language_number = 1; //German
			} elseif ( 'es' === $settingd_tab_data['cat_language'] ) {
				$language_number = 2; //Spanish
			} elseif ( 'fr' === $settingd_tab_data['cat_language'] ) {
				$language_number = 3; //French
			} elseif ( 'ru' === $settingd_tab_data['cat_language'] ) {
				$language_number = 4; //Russian
			}
		}
		$categories_in_all_lang = elex_fpf_get_google_cats_for_attr_map();
		if ( $google_cats ) {
			foreach ( $google_cats as $google_category ) {
				$check = explode( '-', $google_category );
				$cat   = trim( $check[1] );
				
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['apparel'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['age_group'] ) ) {
						$required_attr['age_group'] = $google_attr['Detailed product description']['age_group'];
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						   $required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						   $required_attr['gender'] = $google_attr['Detailed product description']['gender'];
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
					}
					if ( isset( $google_attr['Detailed product description']['size'] ) ) {
						$required_attr['size'] = $google_attr['Detailed product description']['size'];
					}
					if ( isset( $google_attr['Detailed product description']['pattern'] ) ) {
						$required_attr['pattern'] = $google_attr['Detailed product description']['pattern'];
					}
					if ( isset( $google_attr['Detailed product description']['style'] ) ) {
						$required_attr['style'] = $google_attr['Detailed product description']['style'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['home'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
					}
					if ( isset( $google_attr['Detailed product description']['decor_style'] ) ) {
						$required_attr['decor_style'] = $google_attr['Detailed product description']['decor_style'];
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
					}
					if ( isset( $google_attr['Detailed product description']['pattern'] ) ) {
						$required_attr['pattern'] = $google_attr['Detailed product description']['pattern'];
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['furniture'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
					}
					if ( isset( $google_attr['Detailed product description']['decor_style'] ) ) {
						$required_attr['decor_style'] = $google_attr['Detailed product description']['decor_style'];
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
					}
					if ( isset( $google_attr['Detailed product description']['pattern'] ) ) {
						$required_attr['pattern'] = $google_attr['Detailed product description']['pattern'];
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Detailed product description']['finish'] ) ) {
						$required_attr['finish'] = $google_attr['Detailed product description']['finish'];
					}
					if ( isset( $google_attr['Detailed product description']['is_assembly_required'] ) ) {
						$required_attr['is_assembly_required'] = $google_attr['Detailed product description']['is_assembly_required'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['home_garden_line_bedding'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['decor_style'] ) ) {
						$required_attr['decor_style'] = $google_attr['Detailed product description']['decor_style'];
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
					}
					if ( isset( $google_attr['Detailed product description']['pattern'] ) ) {
						$required_attr['pattern'] = $google_attr['Detailed product description']['pattern'];
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Detailed product description']['size'] ) ) {
						$required_attr['size'] = $google_attr['Detailed product description']['size'];
					}
					if ( isset( $google_attr['Home']['thread_count'] ) ) {
						$required_attr['thread_count'] = $google_attr['Home']['thread_count'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['home_garden_house_appliance'][ $language_number ], 0 ) ) || ( 0 === strpos( $cat, $categories_in_all_lang['home_garden_kitchen_dining'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
					}
					if ( isset( $google_attr['Detailed product description']['product_depth'] ) ) {
						$required_attr['product_depth'] = $google_attr['Detailed product description']['product_depth'];
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Detailed product description']['product_weight'] ) ) {
						$required_attr['product_weight'] = $google_attr['Detailed product description']['product_weight'];
					}
					if ( isset( $google_attr['Detailed product description']['capacity'] ) ) {
						$required_attr['capacity'] = $google_attr['Detailed product description']['capacity'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['home_garden_house_cleaning'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['ingredients'] ) ) {
						$required_attr['ingredients'] = $google_attr['Detailed product description']['ingredients'];
					}
					if ( isset( $google_attr['Detailed product description']['product_form'] ) ) {
						$required_attr['product_form'] = $google_attr['Detailed product description']['product_form'];
					}
					if ( isset( $google_attr['Detailed product description']['scent'] ) ) {
						$required_attr['scent'] = $google_attr['Detailed product description']['scent'];
					}
					if ( isset( $google_attr['Home']['recommended_use'] ) ) {
						$required_attr['recommended_use'] = $google_attr['Home']['recommended_use'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['apparel_accessory_jewel'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['age_group'] ) ) {
						$required_attr['age_group'] = $google_attr['Detailed product description']['age_group'];
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						$required_attr['gender'] = $google_attr['Detailed product description']['gender'];
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
					}
					if ( isset( $google_attr['Detailed product description']['style'] ) ) {
						$required_attr['style'] = $google_attr['Detailed product description']['style'];
					}
					if ( ( 0 !== strpos( $cat, $categories_in_all_lang['apparel_accessory_jewel_watch'][ $language_number ], 0 ) ) ) {
						if ( isset( $google_attr['Jewelry & Watches']['gemstone'] ) ) {
							$required_attr['gemstone'] = $google_attr['Jewelry & Watches']['gemstone'];
						}
						if ( isset( $google_attr['Detailed product description']['size'] ) ) {
							$required_attr['size'] = $google_attr['Detailed product description']['size'];
						}
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['health_beauty'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['age_group'] ) ) {
						$required_attr['age_group'] = $google_attr['Detailed product description']['age_group'];
					}
					if ( isset( $google_attr['Detailed product description']['capacity'] ) ) {
						$required_attr['capacity'] = $google_attr['Detailed product description']['capacity'];
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						$required_attr['gender'] = $google_attr['Detailed product description']['gender'];
					}
					if ( isset( $google_attr['Detailed product description']['ingredients'] ) ) {
						$required_attr['ingredients'] = $google_attr['Detailed product description']['ingredients'];
					}
					if ( ( 0 === strpos( $cat, $categories_in_all_lang['health_beauty_health_care'][ $language_number ], 0 ) ) ) {
						if ( isset( $google_attr['Health & Beauty']['health_concern'] ) ) {
							$required_attr['health_concern'] = $google_attr['Health & Beauty']['health_concern'];
						}
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronics_comm_teleph_mobile'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
					}
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
					}
					if ( isset( $google_attr['Electronics']['operating_system'] ) ) {
						$required_attr['operating_system'] = $google_attr['Electronics']['operating_system'];
					}
					if ( isset( $google_attr['Electronics']['screen_size'] ) ) {
						$required_attr['screen_size'] = $google_attr['Electronics']['screen_size'];
					}
					if ( isset( $google_attr['Electronics']['storage_capacity'] ) ) {
						$required_attr['storage_capacity'] = $google_attr['Electronics']['storage_capacity'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronics_accessories'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
					}
					if ( isset( $google_attr['Electronics']['compatible_devices'] ) ) {
						$required_attr['compatible_devices'] = $google_attr['Electronics']['compatible_devices'];
					}
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronics_computers'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
					}
					if ( isset( $google_attr['Electronics']['operating_system'] ) ) {
						$required_attr['operating_system'] = $google_attr['Electronics']['operating_system'];
					}
					if ( isset( $google_attr['Electronics']['screen_size'] ) ) {
						$required_attr['screen_size'] = $google_attr['Electronics']['screen_size'];
					}
					if ( isset( $google_attr['Electronics']['storage_capacity'] ) ) {
						$required_attr['storage_capacity'] = $google_attr['Electronics']['storage_capacity'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronincs_video_game'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
					}
					if ( isset( $google_attr['Electronics']['video_game_platform'] ) ) {
						$required_attr['video_game_platform'] = $google_attr['Electronics']['video_game_platform'];
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
					}
					if ( isset( $google_attr['Detailed product description']['age_group'] ) ) {
						$required_attr['age_group'] = $google_attr['Detailed product description']['age_group'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['software'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Electronics']['number_of_licenses'] ) ) {
						$required_attr['number_of_licenses'] = $google_attr['Electronics']['number_of_licenses'];
					}
					if ( isset( $google_attr['Electronics']['software_system_requirements'] ) ) {
						$required_attr['software_system_requirements'] = $google_attr['Electronics']['software_system_requirements'];
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronincs_print_copy_scan'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_depth'] ) ) {
						$required_attr['product_depth'] = $google_attr['Detailed product description']['product_depth'];
						unset( $google_attr['Detailed product description']['product_depth'] );
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
						unset( $google_attr['Product identifiers']['brand'] );
					}
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
						unset( $google_attr['Electronics']['model'] );
					}
					if ( isset( $google_attr['Electronics']['resolution'] ) ) {
						$required_attr['resolution'] = $google_attr['Electronics']['resolution'];
						unset( $google_attr['Electronics']['resolution'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronics_video_computer'][ $language_number ], 0 ) ) || ( 0 === strpos( $cat, $categories_in_all_lang['electronics_video_satellite_tv'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['display_technology'] ) ) {
						$required_attr['display_technology'] = $google_attr['Detailed product description']['display_technology'];
						unset( $google_attr['Detailed product description']['display_technology'] );
					}
					if ( isset( $google_attr['Electronics']['resolution'] ) ) {
						$required_attr['resolution'] = $google_attr['Electronics']['resolution'];
						unset( $google_attr['Electronics']['resolution'] );
					}
					if ( isset( $google_attr['Electronics']['screen_size'] ) ) {
						$required_attr['screen_size'] = $google_attr['Electronics']['screen_size'];
						unset( $google_attr['Electronics']['screen_size'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_depth'] ) ) {
						$required_attr['product_depth'] = $google_attr['Detailed product description']['product_depth'];
						unset( $google_attr['Detailed product description']['product_depth'] );
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
						unset( $google_attr['Product identifiers']['brand'] );
					}
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
						unset( $google_attr['Electronics']['model'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['electronincs_video_projector'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['display_technology'] ) ) {
						$required_attr['display_technology'] = $google_attr['Detailed product description']['display_technology'];
						unset( $google_attr['Detailed product description']['display_technology'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_depth'] ) ) {
						$required_attr['product_depth'] = $google_attr['Detailed product description']['product_depth'];
						unset( $google_attr['Detailed product description']['product_depth'] );
					}
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
						unset( $google_attr['Product identifiers']['brand'] );
					}
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
						unset( $google_attr['Electronics']['model'] );
					}
					if ( isset( $google_attr['Electronics']['resolution'] ) ) {
						$required_attr['resolution'] = $google_attr['Electronics']['resolution'];
						unset( $google_attr['Electronics']['resolution'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['cameras'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Product identifiers']['brand'] ) ) {
						$required_attr['brand'] = $google_attr['Product identifiers']['brand'];
						unset( $google_attr['Product identifiers']['brand'] );
					}
					if ( isset( $google_attr['Electronics']['model'] ) ) {
						$required_attr['model'] = $google_attr['Electronics']['model'];
						unset( $google_attr['Electronics']['model'] );
					}
					if ( isset( $google_attr['Electronics']['digital_zoom'] ) ) {
						$required_attr['digital_zoom'] = $google_attr['Electronics']['digital_zoom'];
						unset( $google_attr['Electronics']['digital_zoom'] );
					}
					if ( isset( $google_attr['Electronics']['megapixels'] ) ) {
						$required_attr['megapixels'] = $google_attr['Electronics']['megapixels'];
						unset( $google_attr['Electronics']['megapixels'] );
					}
					if ( isset( $google_attr['Electronics']['optical_zoom'] ) ) {
						$required_attr['optical_zoom'] = $google_attr['Electronics']['optical_zoom'];
						unset( $google_attr['Electronics']['optical_zoom'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['baby_toddler_nursing_feeding'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						$required_attr['gender'] = $google_attr['Detailed product description']['gender'];
						unset( $google_attr['Detailed product description']['gender'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
						unset( $google_attr['Detailed product description']['material'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['size'] ) ) {
						$required_attr['size'] = $google_attr['Detailed product description']['size'];
						unset( $google_attr['Detailed product description']['size'] );
					}
					if ( isset( $google_attr['Detailed product description']['decor_style'] ) ) {
						$required_attr['decor_style'] = $google_attr['Detailed product description']['decor_style'];
						unset( $google_attr['Detailed product description']['decor_style'] );
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
						unset( $google_attr['Detailed product description']['color'] );
					}
					if ( isset( $google_attr['Baby Products']['baby_food_stage'] ) ) {
						$required_attr['baby_food_stage'] = $google_attr['Baby Products']['baby_food_stage'];
						unset( $google_attr['Baby Products']['baby_food_stage'] );
					}
					if ( isset( $google_attr['Baby Products']['age_range'] ) ) {
						$required_attr['age_range'] = $google_attr['Baby Products']['age_range'];
						unset( $google_attr['Baby Products']['age_range'] );
					}
					if ( isset( $google_attr['Baby Products']['maximum_weight'] ) ) {
						$required_attr['maximum_weight'] = $google_attr['Baby Products']['maximum_weight'];
						unset( $google_attr['Baby Products']['maximum_weight'] );
					}
					if ( isset( $google_attr['Baby Products']['minimum_weight'] ) ) {
						$required_attr['minimum_weight'] = $google_attr['Baby Products']['minimum_weight'];
						unset( $google_attr['Baby Products']['minimum_weight'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['toys'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
						unset( $google_attr['Detailed product description']['material'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						$required_attr['gender'] = $google_attr['Detailed product description']['gender'];
						unset( $google_attr['Detailed product description']['gender'] );
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
						unset( $google_attr['Detailed product description']['color'] );
					}
					if ( isset( $google_attr['Baby Products']['age_range'] ) ) {
						$required_attr['age_range'] = $google_attr['Baby Products']['age_range'];
						unset( $google_attr['Baby Products']['age_range'] );
					}
					if ( isset( $google_attr['Baby Products']['maximum_weight'] ) ) {
						$required_attr['maximum_weight'] = $google_attr['Baby Products']['maximum_weight'];
						unset( $google_attr['Baby Products']['maximum_weight'] );
					}
					if ( isset( $google_attr['Baby Products']['minimum_weight'] ) ) {
						$required_attr['minimum_weight'] = $google_attr['Baby Products']['minimum_weight'];
						unset( $google_attr['Baby Products']['minimum_weight'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['baby_toddler_transport'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
						unset( $google_attr['Detailed product description']['material'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						$required_attr['gender'] = $google_attr['Detailed product description']['gender'];
						unset( $google_attr['Detailed product description']['gender'] );
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
						unset( $google_attr['Detailed product description']['color'] );
					}
					if ( isset( $google_attr['Detailed product description']['is_assembly_required'] ) ) {
						$required_attr['is_assembly_required'] = $google_attr['Detailed product description']['is_assembly_required'];
						unset( $google_attr['Detailed product description']['is_assembly_required'] );
					}
					if ( isset( $google_attr['Baby Products']['maximum_weight'] ) ) {
						$required_attr['maximum_weight'] = $google_attr['Baby Products']['maximum_weight'];
						unset( $google_attr['Baby Products']['maximum_weight'] );
					}
					if ( isset( $google_attr['Baby Products']['minimum_weight'] ) ) {
						$required_attr['minimum_weight'] = $google_attr['Baby Products']['minimum_weight'];
						unset( $google_attr['Baby Products']['minimum_weight'] );
					}
				}
				if ( ( 0 === strpos( $cat, $categories_in_all_lang['baby_toddler_diaper'][ $language_number ], 0 ) ) || ( 0 === strpos( $cat, $categories_in_all_lang['baby_toddler_potty_training'][ $language_number ], 0 ) ) ) {
					if ( isset( $google_attr['Detailed product description']['product_length'] ) ) {
						$required_attr['product_length'] = $google_attr['Detailed product description']['product_length'];
						unset( $google_attr['Detailed product description']['product_length'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_height'] ) ) {
						$required_attr['product_height'] = $google_attr['Detailed product description']['product_height'];
						unset( $google_attr['Detailed product description']['product_height'] );
					}
					if ( isset( $google_attr['Detailed product description']['material'] ) ) {
						$required_attr['material'] = $google_attr['Detailed product description']['material'];
						unset( $google_attr['Detailed product description']['material'] );
					}
					if ( isset( $google_attr['Detailed product description']['product_width'] ) ) {
						$required_attr['product_width'] = $google_attr['Detailed product description']['product_width'];
						unset( $google_attr['Detailed product description']['product_width'] );
					}
					if ( isset( $google_attr['Detailed product description']['gender'] ) ) {
						$required_attr['gender'] = $google_attr['Detailed product description']['gender'];
						unset( $google_attr['Detailed product description']['gender'] );
					}
					if ( isset( $google_attr['Detailed product description']['color'] ) ) {
						$required_attr['color'] = $google_attr['Detailed product description']['color'];
						unset( $google_attr['Detailed product description']['color'] );
					}
					if ( isset( $google_attr['Detailed product description']['package_quantity'] ) ) {
						$required_attr['package_quantity'] = $google_attr['Detailed product description']['package_quantity'];
						unset( $google_attr['Detailed product description']['package_quantity'] );
					}
					if ( isset( $google_attr['Baby Products']['age_range'] ) ) {
						$required_attr['age_range'] = $google_attr['Baby Products']['age_range'];
						unset( $google_attr['Baby Products']['age_range'] );
					}
					if ( isset( $google_attr['Detailed product description']['size'] ) ) {
						$required_attr['size'] = $google_attr['Detailed product description']['size'];
						unset( $google_attr['Detailed product description']['size'] );
					}
				}
			}
		}
		$product_attr         = $this->elex_fpf_get_product_attributes();
		$required_google_attr = array();
		if ( ! empty( $saved_google_attr ) ) {
			foreach ( $saved_google_attr as $attr ) {
				if ( in_array( $attr, array_keys( $required_attr_always ) ) ) {
					$required_google_attr[ $attr ] = $required_attr_always [ $attr ];
					unset( $required_attr_always [ $attr ] );
				}
			}
			if ( ! empty( $required_attr_always ) ) {
				$required_google_attr = array_merge( $required_google_attr, $required_attr_always );
			}
		} else {
			$required_google_attr = $required_attr_always ;
		}
	
		function sort_attr_lists( $a, $subkey ) {
			foreach ( $a as $k => $v ) {
				$b[ $k ] = strtolower( $v[ $subkey ] );
			}
			asort( $b );
			foreach ( $b as $key => $val ) {
				$c[ $key ] = $a[ $key ];
			}
			return $c;
		}
		$sorted_product_attr = sort_attr_lists( $product_attr, 'grp_type' );
		$mapping_attr        = array(
			'required_attr_always' => $required_google_attr,
			'required_attr'        => $required_attr, 
			'optional'             => $google_attr,
			'product_attr'         => $sorted_product_attr,
		);
	
	
		return $mapping_attr;
	}

	public function elex_fpf_manage_feed_edit_file() {
		check_ajax_referer( 'ajax-elex-fpf-manage-feed-nonce', '_ajax_elex_fpf_manage_feed_nonce' );
		$prefill_values = array();
		$mapping_attr   = '';
		$file_to_edit   = isset( $_POST['file_to_edit'] ) ? sanitize_text_field( $_POST['file_to_edit'] ) : '';
		$prefill_values = array_merge( $prefill_values, json_decode( elex_fpf_get_feed_data( $file_to_edit, 'start_filter' )[0]['feed_meta_content'], true ) );
		$prefill_values = array_merge( $prefill_values, json_decode( elex_fpf_get_feed_data( $file_to_edit, 'category_select' )[0]['feed_meta_content'], true ) );
		$prefill_values = array_merge( $prefill_values, json_decode( elex_fpf_get_feed_data( $file_to_edit, 'attribute_map' )[0]['feed_meta_content'], true ) );
		$prefill_values = array_merge( $prefill_values, json_decode( elex_fpf_get_feed_data( $file_to_edit, 'filtering_options' )[0]['feed_meta_content'], true ) );
		$prefill_values = array_merge( $prefill_values, json_decode( elex_fpf_get_feed_data( $file_to_edit, 'manage_feed_data' )[0]['feed_meta_content'], true ) );
		if ( isset( $prefill_values['elex_sync_to_fb_for_us'] ) ) {
			$us_country_check = $prefill_values['elex_sync_to_fb_for_us'];
		}
		if ( ! empty( $prefill_values['selected_google_product_cats'] ) ) {
			$selected_google_cats = $prefill_values['selected_google_product_cats'];
		} else {
			$selected_google_cats = $prefill_values['sel_google_cats'];
		}
		$mapping_attr                = $this->elex_fpf_get_mapping_attr( $us_country_check, $selected_google_cats, $prefill_values['sale_country'], $prefill_values['include_variation'], $prefill_values['google_attr'] );
		$mapping_attr['prefill_val'] = $prefill_values;
		die( wp_json_encode( $mapping_attr ) );
	}

	public function elex_fpf_get_product_attributes() {
		$prod_meta = array(
			''                        => array(
				'label'    => '-- Choose --',
				'type'     => '',
				'grp_type' => '',
			),
			'ID'                      => array(
				'label'    => 'Product Id',
				'type'     => '',
				'grp_type' => 'General',
			),
			'price'                   => array(
				'label'    => 'Price',
				'type'     => '',
				'grp_type' => 'General',
			),
			'price_incl_tax'          => array(
				'label'    => 'Price Including Tax',
				'type'     => '',
				'grp_type' => 'General',
			),
			'_regular_price'          => array(
				'label'    => 'Regular Price',
				'type'     => 'meta',
				'grp_type' => 'General',
			),
			'_tax_class'              => array(
				'label'    => 'Tax Class',
				'type'     => 'meta',
				'grp_type' => 'General',
			),
			'_tax_status'             => array(
				'label'    => 'Tax Status',
				'type'     => 'meta',
				'grp_type' => 'General',
			),
			'post_title'              => array(
				'label'    => 'Product Title',
				'type'     => '',
				'grp_type' => 'General',
			),
			'_elex_fpf_brand'         => array(
				'label'    => 'Brand',
				'type'     => 'meta',
				'grp_type' => 'General',
			),
			'_elex_fpf_gtin'          => array(
				'label'    => 'GTIN',
				'type'     => 'meta',
				'grp_type' => 'General',
			),
			
			'_elex_fpf_mpn'           => array(
				'label'    => 'MPN',
				'type'     => 'meta',
				'grp_type' => 'General',
			),

			'_elex_fpf_importer_addr' => array(
				'label'    => 'Importer Addr',
				'type'     => 'meta',
				'grp_type' => 'General',
			),

			'post_content'            => array(
				'label'    => 'Product Description',
				'type'     => '',
				'grp_type' => 'General',
			),
			'post_excerpt'            => array(
				'label'    => 'Product Short Description',
				'type'     => '',
				'grp_type' => 'General',
			),
			'post_author'             => array(
				'label'    => 'Post Author',
				'type'     => '',
				'grp_type' => 'General',
			),
			'prod_category'           => array(
				'label'    => 'Product Category',
				'type'     => '',
				'grp_type' => 'General',
			),
			'product_tags'            => array(
				'label'    => 'Product Tags',
				'type'     => '',
				'grp_type' => 'General',
			),
			'product_type'            => array(
				'label'    => 'Product Type',
				'type'     => '',
				'grp_type' => 'General',
			),
			'permalink'               => array(
				'label'    => 'Permalink',
				'type'     => '',
				'grp_type' => 'General',
			),
			'main_image'              => array(
				'label'    => 'Main Image',
				'type'     => '',
				'grp_type' => 'General',
			),
			'gallery_images'          => array(
				'label'    => 'Product Gallery Images',
				'type'     => '',
				'grp_type' => 'General',
			),
			'wc_currency'             => array(
				'label'    => 'Woocommerce Shop Currency',
				'type'     => '',
				'grp_type' => 'General',
			),
			'_virtual'                => array(
				'label'    => 'Virtual',
				'type'     => 'meta',
				'grp_type' => 'General',
			),
			'review_comment'          => array(
				'label'    => 'Review Comment',
				'type'     => '',
				'grp_type' => 'General',
			),
			'review_count'            => array(
				'label'    => 'Average Review Count',
				'type'     => '',
				'grp_type' => 'General',
			),
			'_sku'                    => array(
				'label'    => 'SKU',
				'type'     => 'meta',
				'grp_type' => 'Inventory',
			),
			'_manage_stock'           => array(
				'label'    => 'Manage Stock',
				'type'     => 'meta',
				'grp_type' => 'Inventory',
			),
			'_stock'                  => array(
				'label'    => 'Stock Quantity',
				'type'     => 'meta',
				'grp_type' => 'Inventory',
			),
			'_stock_status'           => array(
				'label'    => 'Stock Status',
				'type'     => '',
				'grp_type' => 'Inventory',
			),
			'_sold_individually'      => array(
				'label'    => 'Sold Individually',
				'type'     => 'meta',
				'grp_type' => 'Inventory',
			),
			'_backorders'             => array(
				'label'    => 'Allow Backorders',
				'type'     => 'meta',
				'grp_type' => 'Inventory',
			),
			'_height'                 => array(
				'label'    => 'Height',
				'type'     => 'meta',
				'grp_type' => 'Shipping',
			),
			'_width'                  => array(
				'label'    => 'Width',
				'type'     => 'meta',
				'grp_type' => 'Shipping',
			),
			'_length'                 => array(
				'label'    => 'Length',
				'type'     => 'meta',
				'grp_type' => 'Shipping',
			),
			'_weight'                 => array(
				'label'    => 'Weight',
				'type'     => 'meta',
				'grp_type' => 'Shipping',
			),
			'menu_order'              => array(
				'label'    => 'Menu Order',
				'type'     => '',
				'grp_type' => 'Advanced',
			),
			'item_group_id'           => array(
				'label'    => 'Item group ID',
				'type'     => '',
				'grp_type' => 'Advanced',
			),
			'google_category'         => array(
				'label'    => 'Google Category',
				'type'     => '',
				'grp_type' => 'Advanced',
			),
		
		);
		$custom_meta   = $this->elex_fpf_get_custom_meta_keys();
		$product_metas = array_merge( $prod_meta, $custom_meta );
		return $product_metas;
	}

	public function elex_fpf_get_custom_meta_keys() {
		global $wpdb;

		$data         = $wpdb->get_results(
			'SELECT  meta.meta_key  FROM ' . $wpdb->prefix . 'postmeta AS meta, ' . $wpdb->prefix . 'posts' . " AS posts WHERE meta.post_id = posts.id AND posts.post_type LIKE '%product%' 
			GROUP BY meta.meta_key ORDER BY meta.meta_key ASC" 
		);
		$temp_arr     = array();
		$custom_metas = array();
		foreach ( $data as $key ) {
			$temp_arr                       = array();
			$temp_arr['label']              = $key->meta_key;
			$temp_arr['type']               = 'meta';
			$temp_arr['grp_type']           = 'Meta Values';
			$custom_metas[ $key->meta_key ] = $temp_arr;
		}
		return $custom_metas;
	}

	public function elex_fpf_get_google_attributes() {
		return array(
			'Basic product data'                          => array(
				'id'                    => array(
					'label'     => 'Product ID <span style="color:red;">*</span>',
					'feed_name' => 'g:id',
				),
				'title'                 => array(
					'label'     => 'Product title <span style="color:red;">*</span>',
					'feed_name' => 'g:title',
				),
				'description'           => array(
					'label'     => 'Product description <span style="color:red;">*</span>',
					'feed_name' => 'g:description',
				),
				'link'                  => array(
					'label'     => 'Product link <span style="color:red;">*</span>',
					'feed_name' => 'g:link',
				),
				'image_link'            => array(
					'label'     => 'Main image link <span style="color:red;">*</span>',
					'feed_name' => 'g:image_link',
				),

				'additional_image_link' => array(
					'label'     => 'Additional image link',
					'feed_name' => 'g:additional_image_link',
				),
				'mobile_link'           => array(
					'label'     => 'Product mobile link',
					'feed_name' => 'g:mobile_link',
				),
			),

			'Price & availability'                        => array(
				'availability'                    => array(
					'label'     => 'Stock status <span style="color:red;">*</span>',
					'feed_name' => 'g:availability',
				),
				'availability_date'               => array(
					'label'     => 'Availability date',
					'feed_name' => 'g:availability_date',
				),
				'cost_of_goods_sold'              => array(
					'label'     => 'Cost of goods sold',
					'feed_name' => 'g:cost_of_goods_sold',
				),
				'expiration_date'                 => array(
					'label'     => 'Expiration date',
					'feed_name' => 'g:expiration_date',
				),
				'price'                           => array(
					'label'     => 'Price <span style="color:red;">*</span>',
					'feed_name' => 'g:price',
				),
				'sale_price_effective_date'       => array(
					'label'     => 'Sale price effective date',
					'feed_name' => 'g:sale_price_effective_date',
				),
				'unit_pricing_measure'            => array(
					'label'     => 'Unit pricing measure',
					'feed_name' => 'g:unit_pricing_measure',
				),
				'unit_pricing_base_measure'       => array(
					'label'     => 'Unit pricing base measure',
					'feed_name' => 'g:unit_pricing_base_measure',
				),
				'installment'                     => array(
					'label'     => 'Installment',
					'feed_name' => 'g:installment',
				),
				'loyalty_points'                  => array(
					'label'     => 'Loyalty points',
					'feed_name' => 'g:loyalty_points',
				),
				'subscription_cost-period'        => array(
					'label'     => 'Subscription Cost - Period',
					'feed_name' => 'g:subscription_cost-period',
				),
				'subscription_cost-period_length' => array(
					'label'     => 'subscription Coste - Priod Length',
					'feed_name' => 'g:subscription_cost-period_length',
				),
				'subscription_cost-amount'        => array(
					'label'     => 'Subscription Cost - Amount',
					'feed_name' => 'g:subscription_cost-amount',
				),
			),
			'Product category'                            => array(
				'google_product_category' => array(
					'label'     => 'Google product category <span style="color:red;">*</span>',
					'feed_name' => 'g:google_product_category',
				),
				'product_type'            => array(
					'label'     => 'Product type',
					'feed_name' => 'g:product_type',
				),
			),
			'Product identifiers'                         => array(
				'brand' => array(
					'label'     => 'Brand <span style="color:red;">*</span>',
					'feed_name' => 'g:brand',
				),
				'gtin'  => array(
					'label'     => 'GTIN <span style="color:red;">*</span>',
					'feed_name' => 'g:gtin',
				),
				'mpn'   => array(
					'label'     => 'MPN <span style="color:red;">*</span>',
					'feed_name' => 'g:mpn',
				),
			),
			'Detailed product description'                => array(
				'condition'                      => array(
					'label'     => 'Condition <span style="color:red;">*</span>',
					'feed_name' => 'g:condition',
				),
				'adult'                          => array(
					'label'     => 'Adult <span style="color:red;">*</span>',
					'feed_name' => 'g:adult',
				),
				'multipack'                      => array(
					'label'     => 'Multipack',
					'feed_name' => 'g:multipack',
				),
				
				'energy_efficiency_class'        => array(
					'label'     => 'Energy efficiency class',
					'feed_name' => 'g:energy_efficiency_class',
				),
				'min_energy_efficiency_class'    => array(
					'label'     => 'Minimum energy efficiency class',
					'feed_name' => 'g:min_energy_efficiency_class',
				),
				'max_energy_efficiency_class'    => array(
					'label'     => 'Maximum energy efficiency class',
					'feed_name' => 'g:max_energy_efficiency_class',
				),
				'age_group'                      => array(
					'label'     => 'Age group',
					'feed_name' => 'g:age_group',
				),
				'color'                          => array(
					'label'     => 'Color',
					'feed_name' => 'g:color',
				),
				'gender'                         => array(
					'label'     => 'Gender',
					'feed_name' => 'g:gender',
				),
				'material'                       => array(
					'label'     => 'Material',
					'feed_name' => 'g:material',
				),
				'pattern'                        => array(
					'label'     => 'Pattern',
					'feed_name' => 'g:pattern',
				),
				'size'                           => array(
					'label'     => 'Size',
					'feed_name' => 'g:size',
				),
				'size_type'                      => array(
					'label'     => 'Size type',
					'feed_name' => 'g:size_type',
				),
				'size_system'                    => array(
					'label'     => 'Size system',
					'feed_name' => 'g:size_system',
				),
				'item_group_id'                  => array(
					'label'     => 'Item group ID <span style="color:red;">*</span>',
					'feed_name' => 'g:item_group_id',
				),
				'product_detail-section_name'    => array(
					'label'     => 'Product Detail - Section Name',
					'feed_name' => 'g:product_detail-section_name',
				),
				'product_detail-attribute_name'  => array(
					'label'     => 'Product Detail - Attribute Name',
					'feed_name' => 'g:product_detail-attribute_name',
				),
				'product_detail-attribute_value' => array(
					'label'     => 'Product Detail - Attribute Value',
					'feed_name' => 'g:product_detail-attribute_value',
				),
				'product_highlight'              => array(
					'label'     => 'Product Highlight',
					'feed_name' => 'g:product_highlight',
				),
				'additional_features'            => array(
					'label'     => 'Additional features',
					'feed_name' => 'g:additional_features',
				),
				'occasion'                       => array(
					'label'     => 'Occasion',
					'feed_name' => 'g:occasion',
				),
				'standard_features'              => array(
					'label'     => 'Standard features',
					'feed_name' => 'g:standard_features',
				),
				'character'                      => array(
					'label'     => 'Character',
					'feed_name' => 'g:character',
				),
				'fabric_care_instructions'       => array(
					'label'     => 'Fabric care instructions',
					'feed_name' => 'g:fabric_care_instructions',
				),
				'power_type'                     => array(
					'label'     => 'Power type',
					'feed_name' => 'g:power_type',
				),
				'ingredients'                    => array(
					'label'     => 'Ingredients',
					'feed_name' => 'g:ingredients',
				),
				'instructions'                   => array(
					'label'     => 'Instructions',
					'feed_name' => 'g:instructions',
				),
				'is_powered'                     => array(
					'label'     => 'Is powered',
					'feed_name' => 'g:is_powered',
				),
				'product_form'                   => array(
					'label'     => 'Product form',
					'feed_name' => 'g:product_form',
				),
				'scent'                          => array(
					'label'     => 'Scent',
					'feed_name' => 'g:scent',
				),
				'product_height'                 => array(
					'label'     => 'Product height',
					'feed_name' => 'g:product_height',
				),
				'product_length'                 => array(
					'label'     => 'Product length',
					'feed_name' => 'g:product_length',
				),
				'product_width'                  => array(
					'label'     => 'Product width',
					'feed_name' => 'g:product_width',
				),
				'product_depth'                  => array(
					'label'     => 'Product depth',
					'feed_name' => 'g:product_depth',
				),
				'product_weight'                 => array(
					'label'     => 'Product weight',
					'feed_name' => 'g:product_weight',
				),
				'display_technology'             => array(
					'label'     => 'Display technology',
					'feed_name' => 'g:display_technology',
				),
				'battery_life'                   => array(
					'label'     => 'Battery life',
					'feed_name' => 'g:battery_life',
				),
				'watch_band_length'              => array(
					'label'     => 'Watch band length',
					'feed_name' => 'g:watch_band_length',
				),
				'watch_band_material'            => array(
					'label'     => 'Watch band material',
					'feed_name' => 'g:watch_band_material',
				),
				'watch_band_width'               => array(
					'label'     => 'Watch band width',
					'feed_name' => 'g:watch_band_width',
				),
				'mount_type'                     => array(
					'label'     => 'Mount type',
					'feed_name' => 'g:mount_type',
				),
				'sport'                          => array(
					'label'     => 'Sport',
					'feed_name' => 'g:sport',
				),
				'sports_league'                  => array(
					'label'     => 'Sports league',
					'feed_name' => 'g:sports_league',
				),
				'sports_team'                    => array(
					'label'     => 'Sports team',
					'feed_name' => 'g:sports_team',
				),
				'is_assembly_required'           => array(
					'label'     => 'Is assembly required',
					'feed_name' => 'g:is_assembly_required',
				),
				'decor_style'                    => array(
					'label'     => 'Decorative style',
					'feed_name' => 'g:decor_style',
				),
				'package_quantity'               => array(
					'label'     => 'Package quantity',
					'feed_name' => 'g:package_quantity',
				),
				'fill_material'                  => array(
					'label'     => 'Fill material',
					'feed_name' => 'g:fill_material',
				),
				'finish'                         => array(
					'label'     => 'Finish',
					'feed_name' => 'g:finish',
				),
				'mattress_thickness'             => array(
					'label'     => 'Mattress thickness',
					'feed_name' => 'g:mattress_thickness',
				),
				'number_of_drawers'              => array(
					'label'     => 'Number of drawers',
					'feed_name' => 'g:number_of_drawers',
				),
				'number_of_seats'                => array(
					'label'     => 'Number of seats',
					'feed_name' => 'g:number_of_seats',
				),
				'number_of_shelves'              => array(
					'label'     => 'Number of shelves',
					'feed_name' => 'g:number_of_shelves',
				),
				'theme'                          => array(
					'label'     => 'Theme',
					'feed_name' => 'g:theme',
				),
				'educational_focus'              => array(
					'label'     => 'Educational focus',
					'feed_name' => 'g:educational_focus',
				),
				'flavor'                         => array(
					'label'     => 'Flavor',
					'feed_name' => 'g:flavor',
				),
				'capacity'                       => array(
					'label'     => 'Capacity',
					'feed_name' => 'g:capacity',
				),
			),
			'Apparel & Accessories'                       => array(
				'style'                          => array(
					'label'     => 'Style',
					'feed_name' => 'g:style',
				),
				'shoe_width'                     => array(
					'label'     => 'Shoe width',
					'feed_name' => 'g:shoe_width',
				),
				'bra_band_size'                  => array(
					'label'     => 'Bra band size',
					'feed_name' => 'g:bra_band_size',
				),
				'bra_cup_size'                   => array(
					'label'     => 'Bra cup size',
					'feed_name' => 'g:bra_cup_size',
				),
				'chest_size'                     => array(
					'label'     => 'Chest size',
					'feed_name' => 'g:chest_size',
				),
				'closure'                        => array(
					'label'     => 'Closure',
					'feed_name' => 'g:closure',
				),
				'clothing_size_type'             => array(
					'label'     => 'Clothing size type',
					'feed_name' => 'g:clothing_size_type',
				),
				'collar_style'                   => array(
					'label'     => 'Collar style',
					'feed_name' => 'g:collar_style',
				),
				'inseam'                         => array(
					'label'     => 'Inseam',
					'feed_name' => 'g:inseam',
				),
				'is_costume'                     => array(
					'label'     => 'Is costume',
					'feed_name' => 'g:is_costume',
				),
				'is_outfit_set'                  => array(
					'label'     => 'Is outfit set',
					'feed_name' => 'g:is_outfit_set',
				),
				'jean_wash'                      => array(
					'label'     => 'Jean wash',
					'feed_name' => 'g:jean_wash',
				),
				'neckline'                       => array(
					'label'     => 'Neckline',
					'feed_name' => 'g:neckline',
				),
				'pant_fit'                       => array(
					'label'     => 'Pant fit',
					'feed_name' => 'g:pant_fit',
				),
				'sheerness'                      => array(
					'label'     => 'Sheerness',
					'feed_name' => 'g:sheerness',
				),
				'size_system'                    => array(
					'label'     => 'Size system',
					'feed_name' => 'g:size_system',
				),
				'skirt_length'                   => array(
					'label'     => 'Skirt length',
					'feed_name' => 'g:skirt_length',
				),
				'sleeve_length'                  => array(
					'label'     => 'Sleeve length',
					'feed_name' => 'g:sleeve_length',
				),
				'sleeve_length_style'            => array(
					'label'     => 'Sleeve length style',
					'feed_name' => 'g:sleeve_length_style',
				),
				'sleeve_style'                   => array(
					'label'     => 'Sleeve style',
					'feed_name' => 'g:sleeve_style',
				),
				'sock_rise'                      => array(
					'label'     => 'Sock rise',
					'feed_name' => 'g:sock_rise',
				),
				'upper_body_strap_configuration' => array(
					'label'     => 'Upper body strap configuration',
					'feed_name' => 'g:upper_body_strap_configuration',
				),
				'waist_rise'                     => array(
					'label'     => 'Waist rise',
					'feed_name' => 'g:waist_rise',
				),
				'waist_style'                    => array(
					'label'     => 'Waist style',
					'feed_name' => 'g:waist_style',
				),
				'heel_height'                    => array(
					'label'     => 'Heel height',
					'feed_name' => 'g:heel_height',
				),
				'heel_style'                     => array(
					'label'     => 'Heel style',
					'feed_name' => 'g:heel_style',
				),
				'sunglasses_lens_color'          => array(
					'label'     => 'Sunglasses lens color',
					'feed_name' => 'g:sunglasses_lens_color',
				),
				'sunglasses_lens_technology'     => array(
					'label'     => 'Sunglasses lens technology',
					'feed_name' => 'g:sunglasses_lens_technology',
				),
				'sunglasses_width'               => array(
					'label'     => 'Sunglasses width',
					'feed_name' => 'g:sunglasses_width',
				),
				'tie_width'                      => array(
					'label'     => 'Tie width',
					'feed_name' => 'g:tie_width',
				),
			),
			'Home'                                        => array(
				'thread_count'             => array(
					'label'     => 'Thread count',
					'feed_name' => 'g:thread_count',
				),
				'recommended_use'          => array(
					'label'     => 'Recommended use',
					'feed_name' => 'g:recommended_use',
				),
				'light_bulb_type'          => array(
					'label'     => 'Light bulb type',
					'feed_name' => 'g:light_bulb_type',
				),
				'number_of_lights'         => array(
					'label'     => 'Number of lights',
					'feed_name' => 'g:number_of_lights',
				),
				'recommended_rooms'        => array(
					'label'     => 'Recommended rooms',
					'feed_name' => 'g:recommended_rooms',
				),
				'shape'                    => array(
					'label'     => 'Shape',
					'feed_name' => 'g:shape',
				),
				'bed_frame_type'           => array(
					'label'     => 'Bed frame type',
					'feed_name' => 'g:bed_frame_type',
				),
				'comfort_level'            => array(
					'label'     => 'Comfort level',
					'feed_name' => 'g:comfort_level',
				),
				'indoor_outdoor'           => array(
					'label'     => 'Indoor outdoor',
					'feed_name' => 'g:indoor_outdoor',
				),
				'seat_back_height'         => array(
					'label'     => 'Seat back height',
					'feed_name' => 'g:seat_back_height',
				),
				'seat_height'              => array(
					'label'     => 'Seat height',
					'feed_name' => 'g:seat_height',
				),
				'seat_material'            => array(
					'label'     => 'Seat material',
					'feed_name' => 'g:seat_material',
				),
				'is_set'                   => array(
					'label'     => 'Is set',
					'feed_name' => 'g:is_set',
				),
				'pieces_in_set'            => array(
					'label'     => 'Pieces in set',
					'feed_name' => 'g:pieces_in_set',
				),
				'btu'                      => array(
					'label'     => 'British Thermal Units (BTUs)',
					'feed_name' => 'g:btu',
				),
				'fuel_type'                => array(
					'label'     => 'Fuel type',
					'feed_name' => 'g:fuel_type',
				),
				'load_position'            => array(
					'label'     => 'Load position',
					'feed_name' => 'g:load_position',
				),
				'smart_home_compatibility' => array(
					'label'     => 'Smart home compatibility',
					'feed_name' => 'g:smart_home_compatibility',
				),
				'sound_rating'             => array(
					'label'     => 'Sound rating',
					'feed_name' => 'g:sound_rating',
				),
				'volts'                    => array(
					'label'     => 'Volts',
					'feed_name' => 'g:volts',
				),
				'watts'                    => array(
					'label'     => 'Watts',
					'feed_name' => 'g:watts',
				),
				'bag_type'                 => array(
					'label'     => 'Bag type',
					'feed_name' => 'g:bag_type',
				),
				'shelf_life'               => array(
					'label'     => 'Shelf life',
					'feed_name' => 'g:shelf_life',
				),
				'vacuum_type'              => array(
					'label'     => 'Vacuum type',
					'feed_name' => 'g:vacuum_type',
				),
				'warnings'                 => array(
					'label'     => 'Warnings',
					'feed_name' => 'g:Warnings',
				),
			),
			'Jewelry & Watches'                           => array(
				'gemstone'                 => array(
					'label'     => 'Gemstone',
					'feed_name' => 'g:gemstone',
				),
				'chain_length'             => array(
					'label'     => 'Chain length',
					'feed_name' => 'g:chain_length',
				),
				'clasp_type'               => array(
					'label'     => 'Clasp type',
					'feed_name' => 'g:clasp_type',
				),
				'earring_back_finding'     => array(
					'label'     => 'Earring back finding',
					'feed_name' => 'g:earring_back_finding',
				),
				'gemstone_clarity'         => array(
					'label'     => 'Gemstone clarity',
					'feed_name' => 'g:gemstone_clarity',
				),
				'gemstone_color'           => array(
					'label'     => 'Gemstone color',
					'feed_name' => 'g:gemstone_color',
				),
				'gemstone_creation_method' => array(
					'label'     => 'Gemstone creation method',
					'feed_name' => 'g:gemstone_creation_method',
				),
				'gemstone_cut'             => array(
					'label'     => 'Gemstone cut',
					'feed_name' => 'g:gemstone_cut',
				),
				'gemstone_height'          => array(
					'label'     => 'Gemstone height',
					'feed_name' => 'g:gemstone_height',
				),
				'gemstone_length'          => array(
					'label'     => 'Gemstone length',
					'feed_name' => 'g:gemstone_length',
				),
				'gemstone_treatment'       => array(
					'label'     => 'Gemstone treatment',
					'feed_name' => 'g:gemstone_treatment',
				),
				'gemstone_weight'          => array(
					'label'     => 'Gemstone weight',
					'feed_name' => 'g:gemstone_weight',
				),
				'gemstone_width'           => array(
					'label'     => 'Gemstone width',
					'feed_name' => 'g:gemstone_width',
				),
				'inscription'              => array(
					'label'     => 'Inscription',
					'feed_name' => 'g:inscription',
				),
				'jewelry_setting_style'    => array(
					'label'     => 'Jewelry setting style',
					'feed_name' => 'g:jewelry_setting_style',
				),
				'metal_stamp_or_purity'    => array(
					'label'     => 'Metal stamp or purity',
					'feed_name' => 'g:metal_stamp_or_purity',
				),
				'plating_material'         => array(
					'label'     => 'Plating material',
					'feed_name' => 'g:plating_material',
				),
				'total_gemstone_weight'    => array(
					'label'     => 'Total gemstone weight',
					'feed_name' => 'g:total_gemstone_weight',
				),
				'activity'                 => array(
					'label'     => 'Activity',
					'feed_name' => 'g:activity',
				),
				'watch_band_diameter'      => array(
					'label'     => 'Watch band diameter',
					'feed_name' => 'g:watch_band_diameter',
				),
				'watch_case_thickness'     => array(
					'label'     => 'Watch case thickness',
					'feed_name' => 'g:watch_case_thickness',
				),
				'watch_movement_type'      => array(
					'label'     => 'Watch movement type',
					'feed_name' => 'g:watch_movement_type',
				),

			),
			'Health & Beauty'                             => array(
				'health_concern'                  => array(
					'label'     => 'Health concern',
					'feed_name' => 'g:health_concern',
				),
				'absorbency'                      => array(
					'label'     => 'Absorbency',
					'feed_name' => 'g:absorbency',
				),
				'batteries_required'              => array(
					'label'     => 'Batteries required',
					'feed_name' => 'g:batteries_required',
				),
				'body_part'                       => array(
					'label'     => 'Body part',
					'feed_name' => 'g:body_part',
				),
				'dosage'                          => array(
					'label'     => 'Dosage',
					'feed_name' => 'g:dosage',
				),
				'eyewear_rim'                     => array(
					'label'     => 'Eyewear rim',
					'feed_name' => 'g:eyewear_rim',
				),
				'inactive_ingredients'            => array(
					'label'     => 'Inactive ingredients',
					'feed_name' => 'g:inactive_ingredients',
				),
				'ingredient_composition'          => array(
					'label'     => 'Ingredient composition',
					'feed_name' => 'g:ingredient_composition',
				),
				'keywords'                        => array(
					'label'     => 'Keywords',
					'feed_name' => 'g:keywords',
				),
				'lens_material'                   => array(
					'label'     => 'Lens material',
					'feed_name' => 'g:lens_material',
				),
				'lens_tint'                       => array(
					'label'     => 'Lens tint',
					'feed_name' => 'g:lens_tint',
				),
				'lens_type'                       => array(
					'label'     => 'Lens type',
					'feed_name' => 'g:lens_type',
				),
				'nutrient_amount'                 => array(
					'label'     => 'Nutrient amount',
					'feed_name' => 'g:nutrient_amount',
				),
				'nutrient_name'                   => array(
					'label'     => 'Nutrient name',
					'feed_name' => 'g:nutrient_name',
				),
				'nutrient_percentage_daily_value' => array(
					'label'     => 'Nutrient percentage daily value',
					'feed_name' => 'g:nutrient_percentage_daily_value',
				),
				'result_time'                     => array(
					'label'     => 'Result time',
					'feed_name' => 'g:result_time',
				),
				'serving_size'                    => array(
					'label'     => 'Serving size',
					'feed_name' => 'g:serving_size',
				),
				'skin_care_concerns'              => array(
					'label'     => 'Skin care concerns',
					'feed_name' => 'g:skin_care_concerns',
				),
				'skin_type'                       => array(
					'label'     => 'Skin type',
					'feed_name' => 'g:skin_type',
				),
				'spf_value'                       => array(
					'label'     => 'Sun Protection Factor (SPF)',
					'feed_name' => 'g:spf_value',
				),
				'stop_use_indications'            => array(
					'label'     => 'Stop use indications',
					'feed_name' => 'g:stop_use_indications',
				),
				'uv_rating'                       => array(
					'label'     => 'Ultraviolet rating for eyewear',
					'feed_name' => 'g:uv_rating',
				),
				'care_instructions'               => array(
					'label'     => 'Care instructions',
					'feed_name' => 'g:care_instructions',
				),
				'hair_type'                       => array(
					'label'     => 'Hair type',
					'feed_name' => 'g:hair_type',
				),
				'skin_care_concern'               => array(
					'label'     => 'Skin care concern',
					'feed_name' => 'g:skin_care_concern',
				),
				'skin_tone'                       => array(
					'label'     => 'Skin tone',
					'feed_name' => 'g:skin_tone',
				),
				'wig_cap_type'                    => array(
					'label'     => 'Wig cap type',
					'feed_name' => 'g:wig_cap_type',
				),
			),
			'Electronics'                                 => array(
				'model'                         => array(
					'label'     => 'Model',
					'feed_name' => 'g:model',
				),
				'operating_system'              => array(
					'label'     => 'Operating system',
					'feed_name' => 'g:operating_system',
				),
				'screen_size'                   => array(
					'label'     => 'Screen size',
					'feed_name' => 'g:screen_size',
				),
				'storage_capacity'              => array(
					'label'     => 'Storage capacity',
					'feed_name' => 'g:storage_capacity',
				),
				'compatible_devices'            => array(
					'label'     => 'Compatible devices',
					'feed_name' => 'g:compatible_devices',
				),
				'video_game_platform'           => array(
					'label'     => 'Video game platform',
					'feed_name' => 'g:video_game_platform',
				),
				'number_of_licenses'            => array(
					'label'     => 'Number of licenses',
					'feed_name' => 'g:number_of_licenses',
				),
				'software_system_requirements'  => array(
					'label'     => 'Software system requirements',
					'feed_name' => 'g:software_system_requirements',
				),
				'resolution'                    => array(
					'label'     => 'Resolution',
					'feed_name' => 'g:resolution',
				),
				'digital_zoom'                  => array(
					'label'     => 'Digital zoom',
					'feed_name' => 'g:digital_zoom',
				),
				'megapixels'                    => array(
					'label'     => 'Megapixels',
					'feed_name' => 'g:megapixels',
				),
				'optical_zoom'                  => array(
					'label'     => 'Optical zoom',
					'feed_name' => 'g:optical_zoom',
				),
				'bluetooth_technology'          => array(
					'label'     => 'Bluetooth technology',
					'feed_name' => 'g:bluetooth_technology',
				),
				'cell_phone_service_provider'   => array(
					'label'     => 'Cell phone service provider',
					'feed_name' => 'g:cell_phone_service_provider',
				),
				'cellular_band'                 => array(
					'label'     => 'Cellular band',
					'feed_name' => 'g:cellular_band',
				),
				'cellular_generation'           => array(
					'label'     => 'Cellular generation',
					'feed_name' => 'g:cellular_generation',
				),
				'connector_type'                => array(
					'label'     => 'Connector type',
					'feed_name' => 'g:connector_type',
				),
				'front_facing_camera_megapixel' => array(
					'label'     => 'Front facing camera megapixel',
					'feed_name' => 'g:front_facing_camera_megapixel',
				),
				'number_of_sim_card_slots'      => array(
					'label'     => 'Number of sim card slots',
					'feed_name' => 'g:number_of_sim_card_slots',
				),
				'rear_facing_camera_megapixel'  => array(
					'label'     => 'Rear facing camera megapixel',
					'feed_name' => 'g:rear_facing_camera_megapixel',
				),
				'sim_type_supported'            => array(
					'label'     => 'Sim type supported',
					'feed_name' => 'g:sim_type_supported',
				),
				'stand-by_time'                 => array(
					'label'     => 'Stand by time',
					'feed_name' => 'g:stand-by_time',
				),
				'talk_time'                     => array(
					'label'     => 'Talk time',
					'feed_name' => 'g:talk_time',
				),
				'usb_technology'                => array(
					'label'     => 'USB technology',
					'feed_name' => 'g:usb_technology',
				),
				'usb_type'                      => array(
					'label'     => 'USB type',
					'feed_name' => 'g:usb_type',
				),
				'video_resolution'              => array(
					'label'     => 'Video resolution',
					'feed_name' => 'g:video_resolution',
				),
				'watch_case_shape'              => array(
					'label'     => 'Watch case shape',
					'feed_name' => 'g:watch_case_shape',
				),
				'watch_style'                   => array(
					'label'     => 'Watch style',
					'feed_name' => 'g:watch_style',
				),
				'cable_length'                  => array(
					'label'     => 'Cable length',
					'feed_name' => 'g:cable_length',
				),
				'headphone_features'            => array(
					'label'     => 'Headphone features',
					'feed_name' => 'g:headphone_features',
				),
				'maximum_load_weight'           => array(
					'label'     => 'Maximum load weight',
					'feed_name' => 'g:maximum_load_weight',
				),
				'maximum_screen_size'           => array(
					'label'     => 'Maximum screen size',
					'feed_name' => 'g:maximum_screen_size',
				),
				'minimum_screen_size'           => array(
					'label'     => 'Minimum screen size',
					'feed_name' => 'g:minimum_screen_size',
				),
				'wireless_technologies'         => array(
					'label'     => 'Wireless technologies',
					'feed_name' => 'g:wireless_technologies',
				),
				'computer_case_form_factor'     => array(
					'label'     => 'Computer case form factor',
					'feed_name' => 'g:computer_case_form_factor',
				),
				'cpu_socket_type'               => array(
					'label'     => 'CPU socket_type',
					'feed_name' => 'g:cpu_socket_type',
				),
				'graphics_card_model'           => array(
					'label'     => 'Graphics card model',
					'feed_name' => 'g:graphics_card_model',
				),
				'hard_drive_type'               => array(
					'label'     => 'Hard drive type',
					'feed_name' => 'g:hard_drive_type',
				),
				'maximum_supported_ram'         => array(
					'label'     => 'Maximum supported ram',
					'feed_name' => 'g:maximum_supported_ram',
				),
				'motherboard_form_factor'       => array(
					'label'     => 'Motherboard form factor',
					'feed_name' => 'g:motherboard_form_factor',
				),
				'optical_drive'                 => array(
					'label'     => 'Optical drive',
					'feed_name' => 'g:optical_drive',
				),
				'processor_speed'               => array(
					'label'     => 'Processor speed',
					'feed_name' => 'g:processor_speed',
				),
				'processor_type'                => array(
					'label'     => 'Processor type',
					'feed_name' => 'g:processor_type',
				),
				'ram_memory'                    => array(
					'label'     => 'RAM memory',
					'feed_name' => 'g:ram_memory',
				),
				'physical_media_format'         => array(
					'label'     => 'Physical media format',
					'feed_name' => 'g:physical_media_format',
				),
				'release_date'                  => array(
					'label'     => 'Release date',
					'feed_name' => 'g:release_date',
				),
				'required_peripherals'          => array(
					'label'     => 'Required peripherals',
					'feed_name' => 'g:required_peripherals',
				),
				'video_game_genre'              => array(
					'label'     => 'Video game genre',
					'feed_name' => 'g:video_game_genre',
				),
				'video_game_rating'             => array(
					'label'     => 'Video game rating',
					'feed_name' => 'g:video_game_rating',
				),
				'video_game_series'             => array(
					'label'     => 'Video game series',
					'feed_name' => 'g:video_game_series',
				),
				'software_category'             => array(
					'label'     => 'Foftware category',
					'feed_name' => 'g:software_category',
				),
				'software_version'              => array(
					'label'     => 'Software version',
					'feed_name' => 'g:software_version',
				),
				'color_pages_per_minute'        => array(
					'label'     => 'Color pages per minute',
					'feed_name' => 'g:color_pages_per_minute',
				),
				'monochrome_pages_per_minute'   => array(
					'label'     => 'Monochrome pages per minute',
					'feed_name' => 'g:monochrome_pages_per_minute',
				),
				'monochrome_color'              => array(
					'label'     => 'Monochrome color',
					'feed_name' => 'g:monochrome_color',
				),
				'aspect_ratio'                  => array(
					'label'     => 'Aspect ratio',
					'feed_name' => 'g:aspect_ratio',
				),
				'audio_features'                => array(
					'label'     => 'Audio features',
					'feed_name' => 'g:audio_features',
				),
				'audio_power_output'            => array(
					'label'     => 'Audio power output',
					'feed_name' => 'g:audio_power_output',
				),
				'backlight_technology'          => array(
					'label'     => 'Backlight technology',
					'feed_name' => 'g:backlight_technology',
				),
				'maximum_contrast_ratio'        => array(
					'label'     => 'Maximum contrast ratio',
					'feed_name' => 'g:maximum_contrast_ratio',
				),
				'number_of_hdmi_ports'          => array(
					'label'     => 'Number of HDMI ports',
					'feed_name' => 'g:number_of_hdmi_ports',
				),
				'refresh_rate'                  => array(
					'label'     => 'Refresh rate',
					'feed_name' => 'g:refresh_rate',
				),
				'response_time'                 => array(
					'label'     => 'Response time',
					'feed_name' => 'g:response_time',
				),
				'vesa_mounting_standard'        => array(
					'label'     => 'VESA mounting standard',
					'feed_name' => 'g:vesa_mounting_standard',
				),
				'brightness'                    => array(
					'label'     => 'Brightness',
					'feed_name' => 'g:brightness',
				),
				'lamp_life'                     => array(
					'label'     => 'Lamp life',
					'feed_name' => 'g:lamp_life',
				),
				'throw_ratio'                   => array(
					'label'     => 'Throw ratio',
					'feed_name' => 'g:throw_ratio',
				),
				'flash_type'                    => array(
					'label'     => 'Flash type',
					'feed_name' => 'g:flash_type',
				),
				'focal_length'                  => array(
					'label'     => 'Focal length',
					'feed_name' => 'g:focal_length',
				),
				'focal_ratio'                   => array(
					'label'     => 'Focal ratio',
					'feed_name' => 'g:focal_ratio',
				),
				'lens_coating'                  => array(
					'label'     => 'Lens coating',
					'feed_name' => 'g:lens_coating',
				),
				'lens_diameter'                 => array(
					'label'     => 'Lens diameter',
					'feed_name' => 'g:adwordslens_diameter_redirect',
				),
				'lens_filter'                   => array(
					'label'     => 'Lens filter',
					'feed_name' => 'g:lens_filter',
				),
				'maximum_aperture'              => array(
					'label'     => 'Maximum aperture',
					'feed_name' => 'g:maximum_aperture',
				),
				'maximum_shutter_speed'         => array(
					'label'     => 'Maximum shutter speed',
					'feed_name' => 'g:maximum_shutter_speed',
				),
				'minimum_aperture'              => array(
					'label'     => 'Minimum aperture',
					'feed_name' => 'g:minimum_aperture',
				),
				'minimum_shutter_speed'         => array(
					'label'     => 'Minimum shutter speed',
					'feed_name' => 'g:minimum_shutter_speed',
				),
				'self-timer_delay'              => array(
					'label'     => 'Self timer delay',
					'feed_name' => 'g:self-timer_delay',
				),
				'sensor_resolution'             => array(
					'label'     => 'Sensor resolution',
					'feed_name' => 'g:sensor_resolution',
				),
				'shooting_modes'                => array(
					'label'     => 'Shooting modes',
					'feed_name' => 'g:shooting_modes',
				),
			),
			'Baby Products'                               => array(
				'maximum_weight'            => array(
					'label'     => 'Maximum weight',
					'feed_name' => 'g:maximum_weight',
				),
				'minimum_weight'            => array(
					'label'     => 'Minimum weight',
					'feed_name' => 'g:minimum_weight',
				),
				'baby_food_stage'           => array(
					'label'     => 'Baby food stage',
					'feed_name' => 'g:baby_food_stage',
				),
				'age_range'                 => array(
					'label'     => 'Age range',
					'feed_name' => 'g:age_range',
				),
				'allergens'                 => array(
					'label'     => 'Allergens',
					'feed_name' => 'g:allergens',
				),
				'life_stage'                => array(
					'label'     => 'Life stage',
					'feed_name' => 'g:life_stage',
				),
				'baby_carrier_position'     => array(
					'label'     => 'Baby carrier position',
					'feed_name' => 'g:baby_carrier_position',
				),
				'baby_carrier_style'        => array(
					'label'     => 'Baby carrier style',
					'feed_name' => 'g:baby_carrier_style',
				),
				'car_seat_facing_direction' => array(
					'label'     => 'Car seat facing direction',
					'feed_name' => 'g:car_seat_facing_direction',
				),
				'car_seat_max_child_height' => array(
					'label'     => 'Car seat max child height',
					'feed_name' => 'g:car_seat_max_child_height',
				),
				'child_car_seat_style'      => array(
					'label'     => 'Child car seat style',
					'feed_name' => 'g:child_car_seat_style',
				),
				'safety_harness_style'      => array(
					'label'     => 'Safety harness style',
					'feed_name' => 'g:safety_harness_style',
				),
				'stroller_type'             => array(
					'label'     => 'Stroller type',
					'feed_name' => 'g:stroller_type',
				),
				'diaper_type'               => array(
					'label'     => 'Diaper type',
					'feed_name' => 'g:diaper_type',
				),
			),
			'Shopping campaigns and other configurations' => array(
				'adwords_redirect'              => array(
					'label'     => 'Adwords redirect',
					'feed_name' => 'g:adwords_redirect',
				),
				'custom_label_0'                => array(
					'label'     => 'Custom label 0',
					'feed_name' => 'g:custom_label_0',
				),
				'custom_label_1'                => array(
					'label'     => 'Custom label 1',
					'feed_name' => 'g:custom_label_1',
				),
				'custom_label_2'                => array(
					'label'     => 'Custom label 2',
					'feed_name' => 'g:custom_label_2',
				),
				'custom_label_3'                => array(
					'label'     => 'Custom label 3',
					'feed_name' => 'g:custom_label_3',
				),
				'custom_label_4'                => array(
					'label'     => 'Custom label 4',
					'feed_name' => 'g:custom_label_4',
				),
				'promotion_id'                  => array(
					'label'     => 'Promotion ID',
					'feed_name' => 'g:promotion_id',
				),
				'included_destination'          => array(
					'label'     => 'Included destination',
					'feed_name' => 'included_destination',
				),
				'excluded_destination'          => array(
					'label'     => 'Excluded destination',
					'feed_name' => 'g:excluded_destination',
				),
				'shopping_ads_excluded_country' => array(
					'label'     => 'Shopping Ads Excluded Country',
					'feed_name' => 'g:shopping_ads_excluded_country',
				),
				'store_code'                    => array(
					'label'     => 'Store Code',
					'feed_name' => 'g:store_code',
				),
			),
			'Shipping'                                    => array(
				'shipping-price'     => array(
					'label'     => 'Shipping - Price',
					'feed_name' => 'g:shipping-price',
				),
				'shipping-country'   => array(
					'label'     => 'Shipping - Country',
					'feed_name' => 'g:shipping-country',
				),
				'shipping-region'    => array(
					'label'     => 'Shipping - Region',
					'feed_name' => 'g:shipping-region',
				),
				'shipping-service'   => array(
					'label'     => 'Shipping - Service',
					'feed_name' => 'g:shipping-service',
				),
				'shipping_label'     => array(
					'label'     => 'Shipping label',
					'feed_name' => 'g:shipping_label',
				),
				'shipping_weight'    => array(
					'label'     => 'Shipping weight',
					'feed_name' => 'g:shipping_weight',
				),
				'shipping_length'    => array(
					'label'     => 'Shipping length',
					'feed_name' => 'g:shipping_length',
				),
				'shipping_width'     => array(
					'label'     => 'Shipping width',
					'feed_name' => 'g:shipping_width',
				),
				'shipping_height'    => array(
					'label'     => 'Shipping height',
					'feed_name' => 'g:shipping_height',
				),
				'min_handling_time'  => array(
					'label'     => 'Minimum handling time',
					'feed_name' => 'g:min_handling_time',
				),
				'max_handling_time'  => array(
					'label'     => 'Maximum handling time',
					'feed_name' => 'g:max_handling_time',
				),
				'ships_from_country' => array(
					'label'     => 'Ships From Country',
					'feed_name' => 'g:ships_from_country',
				),
				'transit_time_label' => array(
					'label'     => 'Transit Time Label',
					'feed_name' => 'g:transit_time_label',
				),
			),
			'Tax'                                         => array(
				'tax-rate'     => array(
					'label'     => 'Tax - Rate',
					'feed_name' => 'g:tax-rate',
				),
				'tax-country'  => array(
					'label'     => 'Tax - Country',
					'feed_name' => 'g:tax-country',
				),
				'tax-region'   => array(
					'label'     => 'Tax - Region',
					'feed_name' => 'g:tax-region',
				),
				'tax-tax_ship' => array(
					'label'     => 'Tax - Tax on Shipping',
					'feed_name' => 'g:tax_ship',
				),
				'tax_category' => array(
					'label'     => 'Tax category',
					'feed_name' => 'g:tax_category',
				),
			),
		);
	}

	public function elex_fpf_get_google_attributes_us() {
		return array(
			'Sell in USA' => array(
				'quantity_to_sell_on_facebook' => array(
					'label'     => 'Quantity To Sell',
					'feed_name' => 'g:quantity_to_sell_on_facebook',
				),
				'size'                         => array(
					'label'     => 'Size',
					'feed_name' => 'g:size',
				),
			),

		);

	}
	public function elex_fpf_get_google_attributes_in() {
		return array(
			'Sell in India' => array(
				'origin_country'            => array(
					'label'     => 'Origin Country',
					'feed_name' => 'g:origin_country',
				),
				'importer_name'             => array(
					'label'     => 'Importer Name',
					'feed_name' => 'g:importer_name',
				),
				'importer_addr_street1'     => array(
					'label'     => 'Street 1',
					'feed_name' => 'g:importer_addr_street1',
				),
				'importer_addr_street2'     => array(
					'label'     => 'Street 2',
					'feed_name' => 'g:importer_addr_street2',
				),
				'importer_addr_city'        => array(
					'label'     => 'City',
					'feed_name' => 'g:importer_addr_city',
				),
				'importer_addr_region'      => array(
					'label'     => 'Region',
					'feed_name' => 'g:importer_addr_region',
				),
				'importer_addr_postal_code' => array(
					'label'     => 'Postal Code',
					'feed_name' => 'g:importer_addr_postal_code',
				),
				'importer_addr_country'     => array(
					'label'     => 'Importer Country',
					'feed_name' => 'g:importer_addr_country',
				),
				'manufacturer_name'         => array(
					'label'     => 'Manufacturer Name',
					'feed_name' => 'g:manufacturer_name',
				),
				'manufacturer_address'      => array(
					'label'     => 'Manufacturer Address',
					'feed_name' => 'g:manufacturer_address',
				),
				
			
			),

		);
		
	}
	public function elex_fpf_get_product_ids( $cat_cond, $variation ) {

		$product_type = 'true' === $variation ? 'simple,variable' : 'simple';
		$product_ids  = get_posts(
			array(
				'post_type'              => 'product',
				'numberposts'            => -1,
				'post_status'            => 'publish',
				'fields'                 => 'ids',
				'product_type'           => $product_type,
				'suppress_filters'       => true,
				'lazy_load_term_meta'    => true,
				'update_post_meta_cache' => false,
				'update_post_term_cache' => false,
				'tax_query'              => array(
					array(
						'taxonomy' => 'product_cat',
						'field'    => 'term_id',
						'terms'    => trim( $cat_cond, "'" ),
						'operator' => 'IN',
					),
				),
			)
		);
		return $product_ids;
	}
}



new Elex_Fpf_Ajax_Call();
