.
*/
/**
* If this file is called directly, abort.
*/
if (!defined('WPINC'))
{
die;
}
if (!defined('ABSPATH'))
{
exit;
}
/**
* Plugin versionnumber, please do not override.
* Define some constants
*/
define('WOOCOMMERCESEA_PLUGIN_VERSION', '12.1.5');
define('WOOCOMMERCESEA_PLUGIN_NAME', 'woocommerce-product-feed-pro');
define('WOOCOMMERCESEA_PLUGIN_NAME_SHORT', 'woo-product-feed-pro');
if (!defined('WOOCOMMERCESEA_FILE'))
{
define('WOOCOMMERCESEA_FILE', __FILE__);
}
if (!defined('WOOCOMMERCESEA_PATH'))
{
define('WOOCOMMERCESEA_PATH', plugin_dir_path(WOOCOMMERCESEA_FILE));
}
if (!defined('WOOCOMMERCESEA_BASENAME'))
{
define('WOOCOMMERCESEA_BASENAME', plugin_basename(WOOCOMMERCESEA_FILE));
}
if (!defined('WOOCOMMERCESEA_PLUGIN_URL'))
{
define('WOOCOMMERCESEA_PLUGIN_URL', plugins_url() . '/' . WOOCOMMERCESEA_PLUGIN_NAME_SHORT);
}
/**
* Enqueue css assets
*/
function woosea_styles($hook)
{
// Only register and enqueue CSS scripts from within the plugin itself
if (preg_match("/product-feed-pro/i", $hook))
{
wp_register_style('woosea_admin-css', plugins_url('/css/woosea_admin.css', __FILE__), '', WOOCOMMERCESEA_PLUGIN_VERSION);
wp_enqueue_style('woosea_admin-css');
wp_register_style('woosea_jquery_ui-css', plugins_url('/css/jquery-ui.css', __FILE__), '', WOOCOMMERCESEA_PLUGIN_VERSION);
wp_enqueue_style('woosea_jquery_ui-css');
wp_register_style('woosea_jquery_typeahead-css', plugins_url('/css/jquery.typeahead.css', __FILE__), '', WOOCOMMERCESEA_PLUGIN_VERSION);
wp_enqueue_style('woosea_jquery_typeahead-css');
}
}
add_action('admin_enqueue_scripts', 'woosea_styles');
/**
* Strip slashes from POST requests
*/
function stripslashes_recursive($object)
{
return is_array($object) ? array_map('stripslashes_recursive', $object) : stripslashes($object);
}
/**
* Enqueue js assets admin pages
*/
function woosea_scripts($hook)
{
// Enqueue Jquery
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('jquery-ui-calender');
wp_enqueue_script('jquery-ui-datepicker');
// Only register and enqueue JS scripts from within the plugin itself
if (preg_match("/product-feed-pro/i", $hook))
{
// Bootstrap typeahead
wp_register_script('typeahead-js', plugin_dir_url(__FILE__) . 'js/woosea_typeahead.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('typeahead-js');
// JS for adding input field validation
wp_register_script('woosea_validation-js', plugin_dir_url(__FILE__) . 'js/woosea_validation.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_validation-js');
// JS for autocomplete
wp_register_script('woosea_autocomplete-js', plugin_dir_url(__FILE__) . 'js/woosea_autocomplete.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_autocomplete-js');
// JS for adding table rows to the rules page
wp_register_script('woosea_rules-js', plugin_dir_url(__FILE__) . 'js/woosea_rules.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_rules-js');
// JS for adding table rows to the field mappings page
wp_register_script('woosea_field_mapping-js', plugin_dir_url(__FILE__) . 'js/woosea_field_mapping.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_field_mapping-js');
// JS for getting channels
wp_register_script('woosea_channel-js', plugin_dir_url(__FILE__) . 'js/woosea_channel.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_channel-js');
// JS for managing keys
wp_register_script('woosea_key-js', plugin_dir_url(__FILE__) . 'js/woosea_key.js', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_key-js');
}
// JS for manage projects page
wp_register_script('woosea_manage-js', plugin_dir_url(__FILE__) . 'js/woosea_manage.js?yo=12', '', WOOCOMMERCESEA_PLUGIN_VERSION, true);
wp_enqueue_script('woosea_manage-js');
}
add_action('admin_enqueue_scripts', 'woosea_scripts');
/**
* Internationalisation of plugin
*/
function woosea_load_plugin_textdomain()
{
load_plugin_textdomain('woo-product-feed-pro', FALSE, basename(dirname(__FILE__)) . '/languages/');
}
add_action('plugins_loaded', 'woosea_load_plugin_textdomain');
/**
* Required classes
*/
require plugin_dir_path(__FILE__) . 'classes/class-admin-pages-template.php';
require plugin_dir_path(__FILE__) . 'classes/class-cron.php';
require plugin_dir_path(__FILE__) . 'classes/class-get-products.php';
require plugin_dir_path(__FILE__) . 'classes/class-admin-notifications.php';
require plugin_dir_path(__FILE__) . 'classes/class-update-channel.php';
require plugin_dir_path(__FILE__) . 'classes/class-attributes.php';
require plugin_dir_path(__FILE__) . 'classes/class-google-remarketing.php';
/**
* Add links to the plugin page
*/
function woosea_plugin_action_links($links, $file)
{
static $this_plugin;
if (!$this_plugin)
{
$this_plugin = plugin_basename(__FILE__);
}
// check to make sure we are on the correct plugin
if ($file == $this_plugin)
{
$host = '';
if (!empty($_SERVER['HTTP_HOST']))
{
$host = $_SERVER['HTTP_HOST'];
$host = sanitize_text_field($_SERVER['HTTP_HOST']);
}
$plugin_links[] = 'Support';
$plugin_links[] = 'Tutorials';
$plugin_links[] = 'Go Elite';
$plugin_links[] = 'Premium Support';
// add the links to the list of links already there
foreach ($plugin_links as $link)
{
array_unshift($links, $link);
}
}
return $links;
}
add_filter('plugin_action_links', 'woosea_plugin_action_links', 10, 2);
/**
* Get category path for Facebook pixel
*/
function woosea_get_term_parents($id, $taxonomy, $project_taxonomy, $link = false, $nicename = false, $visited = array())
{
// Only add Home to the beginning of the chain when we start buildin the chain
if (empty($visited))
{
$chain = 'Home';
}
else
{
$chain = '';
}
$parent = get_term($id, $taxonomy);
$separator = ' > ';
if (is_wp_error($parent))
return $parent;
if ($parent)
{
if ($nicename)
{
$name = $parent->slug;
}
else
{
$name = $parent->name;
}
if ($parent->parent && ($parent->parent != $parent->term_id) && !in_array($parent->parent, $visited, TRUE))
{
$visited[] = $parent->parent;
$chain .= woosea_get_term_parents($parent->parent, $taxonomy, $separator, $link = false, $nicename, $visited);
}
if ($link)
{
$chain .= $separator . $name;
}
else
{
$chain .= $separator . $name;
}
}
return $chain;
}
/**
* Add Facebook pixel
*/
function woosea_add_facebook_pixel($product = null)
{
if (!is_object($product))
{
global $product;
}
$fb_pagetype = WooSEA_Google_Remarketing::woosea_google_remarketing_pagetype();
$add_facebook_pixel = get_option('add_facebook_pixel');
$add_facebook_capi = get_option('add_facebook_capi');
$viewContent = "";
$event_id = uniqid(rand(), true);
$currency = get_woocommerce_currency();
if ($add_facebook_pixel == "yes")
{
$facebook_pixel_id = get_option("woosea_facebook_pixel_id");
$facebook_capi_token = get_option("woosea_facebook_capi_token");
// Add vulnerability check
if (!is_numeric($facebook_pixel_id))
{
unset($facebook_pixel_id);
}
if (isset($facebook_pixel_id) and ($facebook_pixel_id > 0))
{
// Set Facebook conversion API data
define('FACEBOOK_APP_ACCESS_TOKEN', $facebook_capi_token);
define('FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID', $facebook_pixel_id);
$fb_capi_data["match_keys"] = array();
$fb_capi_data["event_time"] = time();
$fb_capi_data["event_id"] = $event_id;
$fb_capi_data["user_data"]["client_ip_address"] = WC_Geolocation::get_ip_address();
if (!isset($_SERVER['HTTP_USER_AGENT']))
{
$_SERVER['HTTP_USER_AGENT'] = "Unknown";
}
$fb_capi_data["user_data"]["client_user_agent"] = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
$fb_capi_data["action_source"] = "website";
$fb_capi_data["event_source_url"] = sanitize_text_field(home_url($_SERVER['REQUEST_URI']));
if ($fb_pagetype == "product")
{
if (!empty($product->get_price()))
{
$fb_prodid = get_the_id();
$product_name = $product->get_name();
$product_name = str_replace("\"", "", $product_name);
$product_name = str_replace("'", "", $product_name);
$cats = "";
$all_cats = get_the_terms($fb_prodid, 'product_cat');
if (!empty($all_cats))
{
foreach ($all_cats as $key => $category)
{
$cats .= $category->name . ",";
}
}
// strip last comma
$cats = rtrim($cats, ",");
$cats = str_replace("&", "&", $cats);
$cats = str_replace("\"", "", $cats);
$cats = str_replace("'", "", $cats);
if (!empty($fb_prodid))
{
if (!$product)
{
return -1;
}
if ($product->is_type('variable'))
{
// We should first check if there are any _GET parameters available
// When there are not we are on a variable product page but not on a specific variable one
// In that case we need to put in the AggregateOffer structured data
$variation_id = woosea_find_matching_product_variation($product, sanitize_text_field($_GET));
$nr_get = count($_GET);
// This is a variant product
if (($nr_get > 0) and ($variation_id > 0))
{
$variable_product = wc_get_product($variation_id);
// for variants use the variation_id and not the item_group_id
// otherwise Google will disapprove the items due to itemID mismatches
$fb_prodid = $variation_id;
if (is_object($variable_product))
{
$product_price = $variable_product->get_price();
$fb_price = $product_price;
}
else
{
// AggregateOffer
$prices = $product->get_variation_prices();
$lowest = reset($prices['price']);
$highest = end($prices['price']);
if ($lowest === $highest)
{
$fb_price = wc_format_localized_price($lowest);
}
else
{
$fb_lowprice = wc_format_localized_price($lowest);
$fb_highprice = wc_format_localized_price($highest);
$fb_price = $fb_lowprice;
}
}
$fb_price = floatval(str_replace(',', '.', str_replace(',', '.', $fb_price)));
$viewContent = "fbq(\"track\",\"ViewContent\",{content_category:\"$cats\", content_name:\"$product_name\", content_type:\"product\", content_ids:[\"$fb_prodid\"], value:\"$fb_price\", currency:\"$currency\"},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "ViewContent";
$fb_capi_data["custom_data"]["content_ids"] = $fb_prodid;
$fb_capi_data["custom_data"]["content_name"] = $product_name;
$fb_capi_data["custom_data"]["content_category"] = $cats;
$fb_capi_data["custom_data"]["currency"] = $currency;
$fb_capi_data["custom_data"]["value"] = $fb_price;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
else
{
// This is a parent variable product
// Since these are not allowed in the feed, at the variations product ID's
// Get children product variation IDs in an array
$woosea_content_ids = "variation";
$woosea_content_ids = get_option('add_facebook_pixel_content_ids');
if ($woosea_content_ids == "variation")
{
$children_ids = $product->get_children();
$content = "";
foreach ($children_ids as $id)
{
$content .= '\'' . $id . '\',';
//$content .= $id.',';
}
}
else
{
$content = '\'' . $fb_prodid . '\'';
}
$content = rtrim($content, ",");
$prices = $product->get_variation_prices();
$lowest = reset($prices['price']);
$highest = end($prices['price']);
if ($lowest === $highest)
{
$fb_price = wc_format_localized_price($lowest);
}
else
{
$fb_lowprice = wc_format_localized_price($lowest);
$fb_highprice = wc_format_localized_price($highest);
$fb_price = $fb_lowprice;
}
$fb_price = floatval(str_replace(',', '.', str_replace(',', '.', $fb_price)));
$viewContent = "fbq(\"track\",\"ViewContent\",{content_category:\"$cats\", content_name:\"$product_name\", content_type:\"product_group\", content_ids:[$content], value:\"$fb_price\", currency:\"$currency\"},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "ViewContent";
$fb_capi_data["custom_data"]["content_ids"] = $fb_prodid;
$fb_capi_data["custom_data"]["content_name"] = $product_name;
$fb_capi_data["custom_data"]["content_category"] = $cats;
$fb_capi_data["custom_data"]["currency"] = $currency;
$fb_capi_data["custom_data"]["value"] = $fb_price;
$fb_capi_data["custom_data"]["content_type"] = "product_group";
}
}
else
{
// This is a simple product page
$fb_price = wc_format_localized_price($product->get_price());
$fb_price = floatval(str_replace(',', '.', str_replace(',', '.', $fb_price)));
$viewContent = "fbq(\"track\",\"ViewContent\",{content_category:\"$cats\", content_name:\"$product_name\", content_type:\"product\", content_ids:[\"$fb_prodid\"], value:\"$fb_price\", currency:\"$currency\"},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "ViewContent";
$fb_capi_data["custom_data"]["content_ids"] = $fb_prodid;
$fb_capi_data["custom_data"]["content_name"] = $product_name;
$fb_capi_data["custom_data"]["content_category"] = $cats;
$fb_capi_data["custom_data"]["currency"] = $currency;
$fb_capi_data["custom_data"]["value"] = $fb_price;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
}
}
}
elseif ($fb_pagetype == "cart")
{
// This is on the order thank you page
if (isset($_GET['key']) && is_wc_endpoint_url('order-received'))
{
$order_string = sanitize_text_field($_GET['key']);
if (!empty($order_string))
{
$order_id = wc_get_order_id_by_order_key($order_string);
$order = wc_get_order($order_id);
$order_items = $order->get_items();
$currency = get_woocommerce_currency();
$contents = "";
$order_real = wc_format_localized_price($order->get_total());
if (!is_wp_error($order_items))
{
foreach ($order_items as $item_id => $order_item)
{
$prod_id = $order_item->get_product_id();
$variation_id = $order_item->get_variation_id();
if ($variation_id > 0)
{
$prod_id = $variation_id;
}
$prod_quantity = $order_item->get_quantity();
$contents .= "{'id': '$prod_id', 'quantity': $prod_quantity},";
}
}
$contents = rtrim($contents, ",");
$order_real = floatval(str_replace(',', '.', str_replace(',', '.', $order_real)));
$viewContent = "fbq('track','Purchase',{currency:'$currency', value:'$order_real', content_type:'product', contents:[$contents]},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "Purchase";
$fb_capi_data["custom_data"]["content_ids"] = $prod_id;
$fb_capi_data["custom_data"]["currency"] = $currency;
$fb_capi_data["custom_data"]["value"] = $order_real;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
}
else
{
// This is on the cart page itself
$currency = get_woocommerce_currency();
$cart_items = WC()->cart->get_cart();
$cart_quantity = count($cart_items);
$cart_real = 0;
$contents = "";
$cart_total_amount = wc_format_localized_price(WC()->cart->get_cart_contents_total());
$cart_total_amount = floatval(str_replace(',', '.', str_replace(',', '.', $cart_total_amount)));
$checkoutpage = wc_get_checkout_url();
$current_url = get_permalink(get_the_ID());
if (!empty($cart_items))
{
if (!is_wp_error($cart_items))
{
foreach ($cart_items as $cart_id => $cart_item)
{
$prod_id = $cart_item['product_id'];
$product = $cart_item['data'];
$product_name = $product->get_name();
if ($cart_item['variation_id'] > 0)
{
$prod_id = $cart_item['variation_id'];
}
$contents .= '\'' . $prod_id . '\',';
//$contents .= "$prod_id,";
$cart_real = wc_format_localized_price($cart_item['line_total']);
}
$contents = rtrim($contents, ",");
// User is on the billing pages
if ($checkoutpage == $current_url)
{
$viewContent = "fbq(\"track\",\"InitiateCheckout\",{currency:\"$currency\", value:\"$cart_total_amount\", content_type:\"product\", content_ids:[$contents]},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "InitiateCheckout";
$fb_capi_data["custom_data"]["content_ids"] = $contents;
$fb_capi_data["custom_data"]["content_name"] = $product_name;
$fb_capi_data["custom_data"]["currency"] = $currency;
$fb_capi_data["custom_data"]["value"] = $cart_total_amount;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
else
{
// User is on the basket page
$viewContent = "fbq(\"track\",\"AddToCart\",{currency:\"$currency\", value:\"$cart_total_amount\", content_type:\"product\", content_ids:[$contents]},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "AddToCart";
$fb_capi_data["custom_data"]["content_ids"] = $contents;
$fb_capi_data["custom_data"]["content_name"] = $product_name;
$fb_capi_data["custom_data"]["currency"] = $currency;
$fb_capi_data["custom_data"]["value"] = $cart_total_amount;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
}
}
}
}
elseif ($fb_pagetype == "category")
{
$term = get_queried_object();
global $wp_query;
$ids = wp_list_pluck($wp_query->posts, "ID");
$fb_prodid = "";
foreach ($ids as $id)
{
$_product = wc_get_product($id);
if (!$_product)
{
return -1;
}
if ($_product->is_type('simple'))
{
// Add the simple product ID
$fb_prodid .= '\'' . $id . '\',';
}
else
{
// This is a variable product, add variation product ID's
$children_ids = $_product->get_children();
foreach ($children_ids as $id)
{
$fb_prodid .= '\'' . $id . '\',';
$fb_prodid .= '\'' . $id . '\',';
}
}
}
$fb_prodid = rtrim($fb_prodid, ",");
$category_name = $term->name;
$category_path = woosea_get_term_parents($term->term_id, 'product_cat', $project_taxonomy = false, $link = false, $nicename = false, $visited = array());
$viewContent = "fbq(\"track\",\"ViewCategory\",{content_category:'$category_path', content_name:'$category_name', content_type:\"product\", content_ids:\"[$fb_prodid]\"},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "ViewCategory";
$fb_capi_data["custom_data"]["content_ids"] = $ids;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
elseif ($fb_pagetype == "searchresults")
{
$term = get_queried_object();
$search_string = sanitize_text_field($_GET['s']);
global $wp_query;
$ids = wp_list_pluck($wp_query->posts, "ID");
$fb_prodid = "";
foreach ($ids as $id)
{
$_product = wc_get_product($id);
if (!$_product)
{
return -1;
}
$ptype = $_product->get_type();
if ($ptype == "simple")
{
// Add the simple product ID
$fb_prodid .= '\'' . $id . '\',';
}
else
{
// This is a variable product, add variation product ID's
$children_ids = $_product->get_children();
foreach ($children_ids as $id)
{
$fb_prodid .= '\'' . $id . '\',';
//$fb_prodid .= $id.',';
}
}
}
$fb_prodid = rtrim($fb_prodid, ",");
$viewContent = "fbq(\"trackCustom\",\"Search\",{search_string:\"$search_string\", content_type:\"product\", content_ids:\"[$fb_prodid]\"},{eventID:\"$event_id\"});";
// Facebook CAPI data
$fb_capi_data["event_name"] = "Search";
$fb_capi_data["custom_data"]["content_ids"] = $ids;
$fb_capi_data["custom_data"]["content_type"] = "product";
}
else
{
// This is another page than a product page
$fb_capi_data["event_name"] = "ViewContent";
$viewContent = "";
}
?>
30,
'redirection' => 10,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
"cache-control: no-cache",
"Accept: application/json"
),
'body' => $fields,
'cookies' => array()
);
$response = wp_remote_post($url, $args);
}
}
}
}
add_action('wp_footer', 'woosea_add_facebook_pixel');
/**
* Add Google Adwords Remarketing code to footer
*/
function woosea_add_remarketing_tags($product = null)
{
if (!is_object($product))
{
$product = wc_get_product(get_the_ID());
}
$ecomm_pagetype = WooSEA_Google_Remarketing::woosea_google_remarketing_pagetype();
$add_remarketing = get_option('add_remarketing');
if ($add_remarketing == "yes")
{
$adwords_conversion_id = get_option("woosea_adwords_conversion_id");
// Add vulnerability check, unset when no proper comversion ID was inserted
if (!is_numeric($adwords_conversion_id))
{
unset($adwords_conversion_id);
}
if (!empty($adwords_conversion_id))
{
?>
get_price())
{
$ecomm_prodid = get_the_id();
if (!empty($ecomm_prodid))
{
if (!$product)
{
return -1;
}
if ($product->is_type('variable'))
{
// We should first check if there are any _GET parameters available
// When there are not we are on a variable product page but not on a specific variable one
// In that case we need to put in the AggregateOffer structured data
$variation_id = woosea_find_matching_product_variation($product, sanitize_text_field($_GET));
$nr_get = count($_GET);
if ($nr_get > 0)
{
$variable_product = wc_get_product($variation_id);
// for variants use the variation_id and not the item_group_id
// otherwise Google will disapprove the items due to itemID mismatches
$ecomm_prodid = $variation_id;
if (is_object($variable_product))
{
$product_price = $variable_product->get_price();
// ----- remove HTML TAGs -----
//$product_price = preg_replace ('/<[^>]*>/', ' ', $product_price);
$ecomm_price = $product_price;
}
else
{
// AggregateOffer
$prices = $product->get_variation_prices();
$lowest = reset($prices['price']);
$highest = end($prices['price']);
if ($lowest === $highest)
{
$ecomm_price = wc_format_decimal($lowest, wc_get_price_decimals());
}
else
{
$ecomm_lowprice = wc_format_decimal($lowest, wc_get_price_decimals());
$ecomm_highprice = wc_format_decimal($highest, wc_get_price_decimals());
}
}
}
else
{
// When there are no parameters in the URL (so for normal users, not coming via Google Shopping URL's) show the old WooCommwerce JSON
$prices = $product->get_variation_prices();
$lowest = reset($prices['price']);
$highest = end($prices['price']);
if ($lowest === $highest)
{
$ecomm_price = wc_format_decimal($lowest, wc_get_price_decimals());
}
else
{
$ecomm_lowprice = wc_format_decimal($lowest, wc_get_price_decimals());
$ecomm_highprice = wc_format_decimal($highest, wc_get_price_decimals());
$ecomm_price = $ecomm_lowprice;
}
}
}
else
{
$ecomm_price = wc_format_decimal($product->get_price(), wc_get_price_decimals());
}
}
if (isset($ecomm_price))
{
?>
get_items();
$currency = get_woocommerce_currency();
$contents = "";
$order_real = wc_format_localized_price($order->get_total());
if (!is_wp_error($order_items))
{
foreach ($order_items as $item_id => $order_item)
{
$prod_id = $order_item->get_product_id();
$variation_id = $order_item->get_variation_id();
if ($variation_id > 0)
{
$prod_id = $variation_id;
}
$prod_quantity = $order_item->get_quantity();
}
}
$order_real = floatval(str_replace(',', '.', str_replace(',', '.', $order_real)));
}
}
else
{
// This is on the cart page, no purchase yet
// Get the first product from cart and use that product ID
foreach (WC()->cart->get_cart() as $cart_item)
{
$ecomm_prodid = $cart_item['product_id'];
break;
}
if (isset($ecomm_prodid))
{
$currency = get_woocommerce_currency();
$cart_items = WC()->cart->get_cart();
$cart_quantity = count($cart_items);
$cart_total_amount = wc_format_localized_price(WC()->cart->get_cart_contents_total() + WC()->cart->tax_total);
$cart_total_amount = floatval(str_replace(',', '.', str_replace(',', '.', $cart_total_amount)));
?>
"no",
"timestamp" => date('d-m-Y')
);
update_option('woosea_getelite_notification', $get_elite_notice);
}
add_action('wp_ajax_woosea_getelite_notification', 'woosea_getelite_notification');
/**
* Close the get Elite activation notification
**/
function woosea_getelite_active_notification()
{
$get_elite_notice = array(
"show" => "no",
"timestamp" => date('d-m-Y')
);
update_option('woosea_getelite_active_notification', $get_elite_notice);
}
add_action('wp_ajax_woosea_getelite_active_notification', 'woosea_getelite_active_notification');
/**
* Request our plugin users to write a review
**/
function woosea_request_review()
{
// Only request for a review when:
// Plugin activation has been > 1 week
// Active projects > 0
$cron_projects = get_option('cron_projects');
if (!empty($cron_projects))
{
$nr_projects = count($cron_projects);
$first_activation = get_option('woosea_first_activation');
$notification_interaction = get_option('woosea_review_interaction');
$current_time = time();
$show_after = 604800; // Show only after one week
$is_active = $current_time - $first_activation;
$page = sanitize_text_field(basename($_SERVER['REQUEST_URI']));
if (($nr_projects > 0) and ($is_active > $show_after) and ($notification_interaction != "yes"))
{
echo '
';
echo '
Hey, I noticed you have been using our plugin, Product Feed PRO for WooCommerce by AdTribes.io, for over a week now and have created product feed projects with it - that\'s awesome! Could you please do Eva and me a BIG favor and give it a 5-star rating on WordPress? Just to help us spread the word and boost our motivation. We would greatly appreciate if you would do so :) ~ Adtribes.io support team
';
// Global Trade Item Number (GTIN) Field
if (array_key_exists('custom_attributes__woosea_gtin', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_gtin', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_gtin',
'label' => __('GTIN', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the product Global Trade Item Number (GTIN) here.', 'woo-product-feed-pro'),
)
);
}
// MPN Field
if (array_key_exists('custom_attributes__woosea_mpn', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_mpn', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_mpn',
'label' => __('MPN', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the manufacturer product number', 'woo-product-feed-pro'),
)
);
}
// Universal Product Code (UPC) Field
if (array_key_exists('custom_attributes__woosea_upc', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_upc', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_upc',
'label' => __('UPC', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the Universal Product Code (UPC) here.', 'woo-product-feed-pro'),
)
);
}
// International Article Number (EAN) Field
if (array_key_exists('custom_attributes__woosea_ean', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_ean', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_ean',
'label' => __('EAN', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the International Article Number (EAN) here.', 'woo-product-feed-pro'),
)
);
}
// Optimized product custom title Field
if (array_key_exists('custom_attributes__woosea_optimized_title', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_optimized_title', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_optimized_title',
'label' => __('Optimized title', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter a optimized product title.', 'woo-product-feed-pro'),
)
);
}
// Add product condition drop-down
if (array_key_exists('custom_attributes__woosea_condition', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_condition', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_condition',
'label' => __('Product condition', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select the product condition.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'new' => __('new', 'woo-product-feed-pro'),
'refurbished' => __('refurbished', 'woo-product-feed-pro'),
'used' => __('used', 'woo-product-feed-pro'),
'damaged' => __('damaged', 'woo-product-feed-pro'),
)
)
);
}
// Color Field
if (array_key_exists('custom_attributes__woosea_color', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_color', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_color',
'label' => __('Color', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Insert a color.', 'woo-product-feed-pro'),
)
);
}
// Size Field
if (array_key_exists('custom_attributes__woosea_size', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_size', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_size',
'label' => __('Size', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Insert a size.', 'woo-product-feed-pro'),
)
);
}
// Add gender drop-down
if (array_key_exists('custom_attributes__woosea_gender', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_gender', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_gender',
'label' => __('Gender', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select gender.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'female' => __('female', 'woo-product-feed-pro'),
'male' => __('male', 'woo-product-feed-pro'),
'unisex' => __('unisex', 'woo-product-feed-pro'),
)
)
);
}
// Material Field
if (array_key_exists('custom_attributes__woosea_material', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_material', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_material',
'label' => __('Material', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter a material.', 'woo-product-feed-pro'),
)
);
}
// Pattern Field
if (array_key_exists('custom_attributes__woosea_pattern', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_pattern', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_pattern',
'label' => __('Pattern', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter a pattern.', 'woo-product-feed-pro'),
)
);
}
// Add product age_group drop-down
if (array_key_exists('custom_attributes__woosea_age_group', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_age_group', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_age_group',
'label' => __('Age group', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select the product age group.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'newborn' => __('newborn', 'woo-product-feed-pro'),
'infant' => __('infant', 'woo-product-feed-pro'),
'toddler' => __('toddler', 'woo-product-feed-pro'),
'kids' => __('kids', 'woo-product-feed-pro'),
'adult' => __('adult', 'woo-product-feed-pro'),
)
)
);
}
// Unit pricing measure Field
if (array_key_exists('custom_attributes__woosea_unit_pricing_measure', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_unit_pricing_measure', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_unit_pricing_measure',
'label' => __('Unit pricing measure', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter an unit pricing measure.', 'woo-product-feed-pro'),
)
);
}
// Unit pricing base measure Field
if (array_key_exists('custom_attributes__woosea_unit_pricing_base_measure', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_unit_pricing_base_measure', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_unit_pricing_base_measure',
'label' => __('Unit pricing base measure', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter an unit pricing base measure.', 'woo-product-feed-pro'),
)
);
}
// Installment months
if (array_key_exists('custom_attributes__woosea_installment_months', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_installment_months', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_installment_months',
'label' => __('Installment months', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the number of monthly installments the buyer has to pay.', 'woo-product-feed-pro'),
)
);
}
// Installment amount
if (array_key_exists('custom_attributes__woosea_installment_amount', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_installment_amount', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_installment_amount',
'label' => __('Installment amount', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the amount the bbuyer has to pay per month.', 'woo-product-feed-pro'),
)
);
}
// Cost of goods sold
if (array_key_exists('custom_attributes__woosea_cost_of_good_sold', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_cost_of_good_sold', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_cost_of_good_sold',
'label' => __('Cost of goods sold', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the cost of good you are selling.', 'woo-product-feed-pro'),
)
);
}
// Multipack
if (array_key_exists('custom_attributes__woosea_multipack', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_multipack', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_multipack',
'label' => __('Multipack', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter the multipack amount.', 'woo-product-feed-pro'),
)
);
}
// Is bundle
if (array_key_exists('custom_attributes__woosea_is_bundle', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_is_bundle', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_is_bundle',
'label' => __('Is bundle', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select the is bundle value.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'yes' => __('yes', 'woo-product-feed-pro'),
'no' => __('no', 'woo-product-feed-pro'),
)
)
);
}
// Energy efficiency class
if (array_key_exists('custom_attributes__woosea_energy_efficiency_class', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_energy_efficiency_class', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_energy_efficiency_class',
'label' => __('Energy efficiency class', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select the product energy efficiency class.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'A+++' => __('A+++', 'woo-product-feed-pro'),
'A++' => __('A++', 'woo-product-feed-pro'),
'A+' => __('A+', 'woo-product-feed-pro'),
'A' => __('A', 'woo-product-feed-pro'),
'B' => __('B', 'woo-product-feed-pro'),
'C' => __('C', 'woo-product-feed-pro'),
'D' => __('D', 'woo-product-feed-pro'),
'E' => __('E', 'woo-product-feed-pro'),
'F' => __('F', 'woo-product-feed-pro'),
'G' => __('G', 'woo-product-feed-pro'),
)
)
);
}
// Minimum energy efficiency class
if (array_key_exists('custom_attributes__woosea_min_energy_efficiency_class', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_min_energy_efficiency_class', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_min_energy_efficiency_class',
'label' => __('Minimum energy efficiency class', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select the minimum product energy efficiency class.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'A+++' => __('A+++', 'woo-product-feed-pro'),
'A++' => __('A++', 'woo-product-feed-pro'),
'A+' => __('A+', 'woo-product-feed-pro'),
'A' => __('A', 'woo-product-feed-pro'),
'B' => __('B', 'woo-product-feed-pro'),
'C' => __('C', 'woo-product-feed-pro'),
'D' => __('D', 'woo-product-feed-pro'),
'E' => __('E', 'woo-product-feed-pro'),
'F' => __('F', 'woo-product-feed-pro'),
'G' => __('G', 'woo-product-feed-pro'),
)
)
);
}
// Maximum energy efficiency class
if (array_key_exists('custom_attributes__woosea_max_energy_efficiency_class', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_max_energy_efficiency_class', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_max_energy_efficiency_class',
'label' => __('Maximum energy efficiency class', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Select the maximum product energy efficiency class.', 'woo-product-feed-pro'),
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'A+++' => __('A+++', 'woo-product-feed-pro'),
'A++' => __('A++', 'woo-product-feed-pro'),
'A+' => __('A+', 'woo-product-feed-pro'),
'A' => __('A', 'woo-product-feed-pro'),
'B' => __('B', 'woo-product-feed-pro'),
'C' => __('C', 'woo-product-feed-pro'),
'D' => __('D', 'woo-product-feed-pro'),
'E' => __('E', 'woo-product-feed-pro'),
'F' => __('F', 'woo-product-feed-pro'),
'G' => __('G', 'woo-product-feed-pro'),
)
)
);
}
// Is promotion
if (array_key_exists('custom_attributes__woosea_is_promotion', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_is_promotion', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_is_promotion',
'label' => __('Is promotion', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter your promotion ID.', 'woo-product-feed-pro'),
)
);
}
// Custom field 0
if (array_key_exists('custom_attributes__woosea_custom_field_0', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_custom_field_0', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_0',
'label' => __('Custom field 0', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter your custom field 0', 'woo-product-feed-pro'),
)
);
}
// Custom field 1
if (array_key_exists('custom_attributes__woosea_custom_field_1', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_custom_field_1', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_1',
'label' => __('Custom field 1', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter your custom field 1', 'woo-product-feed-pro'),
)
);
}
// Custom field 2
if (array_key_exists('custom_attributes__woosea_custom_field_2', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_custom_field_2', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_2',
'label' => __('Custom field 2', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter your custom field 2', 'woo-product-feed-pro'),
)
);
}
// Custom field 3
if (array_key_exists('custom_attributes__woosea_custom_field_3', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_custom_field_3', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_3',
'label' => __('Custom field 3', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter your custom field 3', 'woo-product-feed-pro'),
)
);
}
// Custom field 4
if (array_key_exists('custom_attributes__woosea_custom_field_4', $extra_attributes) or (!empty(get_post_meta($post->ID, '_woosea_custom_field_4', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_4',
'label' => __('Custom field 4', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Enter your custom field 4', 'woo-product-feed-pro'),
)
);
}
// Exclude product from feed
woocommerce_wp_checkbox(
array(
'id' => '_woosea_exclude_product',
'label' => __('Exclude from feeds', 'woo-product-feed-pro'),
'desc_tip' => 'true',
'description' => __('Check this box if you want this product to be excluded from product feeds.', 'woo-product-feed-pro'),
)
);
echo '
';
}
}
add_action('woocommerce_product_options_general_product_data', 'woosea_custom_general_fields');
/**
* This function saves the input from the extra fields on the single product edit page
*/
function woosea_save_custom_general_fields($post_id)
{
$woocommerce_brand = empty($_POST['_woosea_brand']) ? '' : sanitize_text_field($_POST['_woosea_brand']);
$woocommerce_gtin = empty($_POST['_woosea_gtin']) ? '' : sanitize_text_field($_POST['_woosea_gtin']);
$woocommerce_upc = empty($_POST['_woosea_upc']) ? '' : sanitize_text_field($_POST['_woosea_upc']);
$woocommerce_mpn = empty($_POST['_woosea_mpn']) ? '' : sanitize_text_field($_POST['_woosea_mpn']);
$woocommerce_ean = empty($_POST['_woosea_ean']) ? '' : sanitize_text_field($_POST['_woosea_ean']);
$woocommerce_title = empty($_POST['_woosea_optimized_title']) ? '' : sanitize_text_field($_POST['_woosea_optimized_title']);
$woocommerce_color = empty($_POST['_woosea_color']) ? '' : sanitize_text_field($_POST['_woosea_color']);
$woocommerce_size = empty($_POST['_woosea_size']) ? '' : sanitize_text_field($_POST['_woosea_size']);
$woocommerce_gender = empty($_POST['_woosea_gender']) ? '' : sanitize_text_field($_POST['_woosea_gender']);
$woocommerce_material = empty($_POST['_woosea_material']) ? '' : sanitize_text_field($_POST['_woosea_material']);
$woocommerce_pattern = empty($_POST['_woosea_pattern']) ? '' : sanitize_text_field($_POST['_woosea_pattern']);
$woocommerce_unit_pricing_measure = empty($_POST['_woosea_unit_pricing_measure']) ? '' : sanitize_text_field($_POST['_woosea_unit_pricing_measure']);
$woocommerce_unit_pricing_base_measure = empty($_POST['_woosea_unit_pricing_base_measure']) ? '' : sanitize_text_field($_POST['_woosea_unit_pricing_base_measure']);
$woocommerce_installment_months = empty($_POST['_woosea_installment_months']) ? '' : sanitize_text_field($_POST['_woosea_installment_months']);
$woocommerce_installment_amount = empty($_POST['_woosea_installment_amount']) ? '' : sanitize_text_field($_POST['_woosea_installment_amount']);
$woocommerce_condition = empty($_POST['_woosea_condition']) ? '' : sanitize_text_field($_POST['_woosea_condition']);
$woocommerce_age_group = empty($_POST['_woosea_age_group']) ? '' : sanitize_text_field($_POST['_woosea_age_group']);
$woocommerce_cost_of_good_sold = empty($_POST['_woosea_cost_of_good_sold']) ? '' : sanitize_text_field($_POST['_woosea_cost_of_good_sold']);
$woocommerce_multipack = empty($_POST['_woosea_multipack']) ? '' : sanitize_text_field($_POST['_woosea_multipack']);
$woocommerce_is_bundle = empty($_POST['_woosea_is_bundle']) ? '' : sanitize_text_field($_POST['_woosea_is_bundle']);
$woocommerce_energy_efficiency_class = empty($_POST['_woosea_energy_efficiency_class']) ? '' : sanitize_text_field($_POST['_woosea_energy_efficiency_class']);
$woocommerce_min_energy_efficiency_class = empty($_POST['_woosea_min_energy_efficiency_class']) ? '' : sanitize_text_field($_POST['_woosea_min_energy_efficiency_class']);
$woocommerce_max_energy_efficiency_class = empty($_POST['_woosea_max_energy_efficiency_class']) ? '' : sanitize_text_field($_POST['_woosea_max_energy_efficiency_class']);
$woocommerce_is_promotion = empty($_POST['_woosea_is_promotion']) ? '' : sanitize_text_field($_POST['_woosea_is_promotion']);
$woocommerce_custom_field_0 = empty($_POST['_woosea_custom_field_0']) ? '' : sanitize_text_field($_POST['_woosea_custom_field_0']);
$woocommerce_custom_field_1 = empty($_POST['_woosea_custom_field_1']) ? '' : sanitize_text_field($_POST['_woosea_custom_field_1']);
$woocommerce_custom_field_2 = empty($_POST['_woosea_custom_field_2']) ? '' : sanitize_text_field($_POST['_woosea_custom_field_2']);
$woocommerce_custom_field_3 = empty($_POST['_woosea_custom_field_3']) ? '' : sanitize_text_field($_POST['_woosea_custom_field_3']);
$woocommerce_custom_field_4 = empty($_POST['_woosea_custom_field_4']) ? '' : sanitize_text_field($_POST['_woosea_custom_field_4']);
if (!empty($_POST['_woosea_exclude_product']))
{
$woocommerce_exclude_product = sanitize_text_field($_POST['_woosea_exclude_product']);
}
else
{
$woocommerce_exclude_product = "no";;
}
if (!empty($woocommerce_brand))
update_post_meta($post_id, '_woosea_brand', $woocommerce_brand);
if (!empty($woocommerce_mpn))
update_post_meta($post_id, '_woosea_mpn', esc_attr($woocommerce_mpn));
if (!empty($woocommerce_upc))
update_post_meta($post_id, '_woosea_upc', esc_attr($woocommerce_upc));
if (!empty($woocommerce_ean))
update_post_meta($post_id, '_woosea_ean', esc_attr($woocommerce_ean));
if (!empty($woocommerce_gtin))
update_post_meta($post_id, '_woosea_gtin', esc_attr($woocommerce_gtin));
if (!empty($woocommerce_color))
update_post_meta($post_id, '_woosea_color', esc_attr($woocommerce_color));
if (!empty($woocommerce_size))
update_post_meta($post_id, '_woosea_size', esc_attr($woocommerce_size));
if (!empty($woocommerce_gender))
update_post_meta($post_id, '_woosea_gender', esc_attr($woocommerce_gender));
if (!empty($woocommerce_material))
update_post_meta($post_id, '_woosea_material', esc_attr($woocommerce_material));
if (!empty($woocommerce_pattern))
update_post_meta($post_id, '_woosea_pattern', esc_attr($woocommerce_pattern));
if (!empty($woocommerce_title))
update_post_meta($post_id, '_woosea_optimized_title', $woocommerce_title);
if (!empty($woocommerce_unit_pricing_measure))
update_post_meta($post_id, '_woosea_unit_pricing_measure', $woocommerce_unit_pricing_measure);
if (!empty($woocommerce_unit_pricing_base_measure))
update_post_meta($post_id, '_woosea_unit_pricing_base_measure', $woocommerce_unit_pricing_base_measure);
if (!empty($woocommerce_condition))
update_post_meta($post_id, '_woosea_condition', $woocommerce_condition);
if (!empty($woocommerce_age_group))
update_post_meta($post_id, '_woosea_age_group', $woocommerce_age_group);
if (!empty($woocommerce_installment_months))
update_post_meta($post_id, '_woosea_installment_months', esc_attr($woocommerce_installment_months));
if (!empty($woocommerce_installment_amount))
update_post_meta($post_id, '_woosea_installment_amount', esc_attr($woocommerce_installment_amount));
if (!empty($woocommerce_exclude_product))
update_post_meta($post_id, '_woosea_exclude_product', esc_attr($woocommerce_exclude_product));
if (!empty($woocommerce_cost_of_good_sold))
update_post_meta($post_id, '_woosea_cost_of_good_sold', esc_attr($woocommerce_cost_of_good_sold));
if (!empty($woocommerce_multipack))
update_post_meta($post_id, '_woosea_multipack', esc_attr($woocommerce_multipack));
if (!empty($woocommerce_is_bundle))
update_post_meta($post_id, '_woosea_is_bundle', esc_attr($woocommerce_is_bundle));
if (!empty($woocommerce_energy_efficiency_class))
update_post_meta($post_id, '_woosea_energy_efficiency_class', esc_attr($woocommerce_energy_efficiency_class));
if (!empty($woocommerce_min_energy_efficiency_class))
update_post_meta($post_id, '_woosea_min_energy_efficiency_class', esc_attr($woocommerce_min_energy_efficiency_class));
if (!empty($woocommerce_max_energy_efficiency_class))
update_post_meta($post_id, '_woosea_max_energy_efficiency_class', esc_attr($woocommerce_max_energy_efficiency_class));
if (!empty($woocommerce_is_promotion))
update_post_meta($post_id, '_woosea_is_promotion', $woocommerce_is_promotion);
if (!empty($woocommerce_custom_field_0))
update_post_meta($post_id, '_woosea_custom_field_0', $woocommerce_custom_field_0);
if (!empty($woocommerce_custom_field_1))
update_post_meta($post_id, '_woosea_custom_field_1', $woocommerce_custom_field_1);
if (!empty($woocommerce_custom_field_2))
update_post_meta($post_id, '_woosea_custom_field_2', $woocommerce_custom_field_2);
if (!empty($woocommerce_custom_field_3))
update_post_meta($post_id, '_woosea_custom_field_3', $woocommerce_custom_field_3);
if (!empty($woocommerce_custom_field_4))
update_post_meta($post_id, '_woosea_custom_field_4', $woocommerce_custom_field_4);
}
add_action('woocommerce_process_product_meta', 'woosea_save_custom_general_fields');
/**
* Create the unique identifier fields for variation products
*/
function woosea_custom_variable_fields($loop, $variation_id, $variation)
{
// Check if the option is enabled or not in the pluggin settings
if (get_option('add_unique_identifiers') == "yes")
{
$extra_attributes = get_option('woosea_extra_attributes');
// Variation Brand field
if (array_key_exists('custom_attributes__woosea_brand', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_brand', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_brand[' . $loop . ']',
'label' => __(' Brand', 'woo-product-feed-pro'),
'placeholder' => 'Brand',
'desc_tip' => 'true',
'description' => __('Enter the product Brand here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_brand', true),
'wrapper_class' => 'form-row-full',
)
);
}
// Variation GTIN field
if (array_key_exists('custom_attributes__woosea_gtin', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_gtin', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_gtin[' . $loop . ']',
'label' => __(' GTIN', 'woo-product-feed-pro'),
'placeholder' => 'GTIN',
'desc_tip' => 'true',
'description' => __('Enter the product GTIN here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_gtin', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Variation MPN field
if (array_key_exists('custom_attributes__woosea_mpn', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_mpn', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_mpn[' . $loop . ']',
'label' => __(' MPN', 'woo-product-feed-pro'),
'placeholder' => 'Manufacturer Product Number',
'desc_tip' => 'true',
'description' => __('Enter the MPN here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_mpn', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Variation UPC field
if (array_key_exists('custom_attributes__woosea_upc', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_upc', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_upc[' . $loop . ']',
'label' => __(' UPC', 'woo-product-feed-pro'),
'placeholder' => 'UPC',
'desc_tip' => 'true',
'description' => __('Enter the product UPC here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_upc', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Variation EAN field
if (array_key_exists('custom_attributes__woosea_ean', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_ean', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_ean[' . $loop . ']',
'label' => __(' EAN', 'woo-product-feed-pro'),
'placeholder' => 'EAN',
'desc_tip' => 'true',
'description' => __('Enter the product EAN here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_ean', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Color field
if (array_key_exists('custom_attributes__woosea_color', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_color', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_color[' . $loop . ']',
'label' => __(' Color', 'woo-product-feed-pro'),
'placeholder' => 'Color',
'desc_tip' => 'true',
'description' => __('Enter the product Color here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_color', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Size field
if (array_key_exists('custom_attributes__woosea_size', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_size', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_size[' . $loop . ']',
'label' => __(' Size', 'woo-product-feed-pro'),
'placeholder' => 'Size',
'desc_tip' => 'true',
'description' => __('Enter the product Size here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_size', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Add Gender drop-down
if (array_key_exists('custom_attributes__woosea_gender', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_gender', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_gender[' . $loop . ']',
'label' => __('Gender', 'woo-product-feed-pro'),
'placeholder' => 'Gender',
'desc_tip' => 'true',
'description' => __('Select the gender.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_gender', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'female' => __('female', 'woo-product-feed-pro'),
'male' => __('male', 'woo-product-feed-pro'),
'unisex' => __('unisex', 'woo-product-feed-pro'),
)
)
);
}
// Material field
if (array_key_exists('custom_attributes__woosea_material', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_material', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_material[' . $loop . ']',
'label' => __(' Material', 'woo-product-feed-pro'),
'placeholder' => 'Material',
'desc_tip' => 'true',
'description' => __('Enter the product Material here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_material', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Pattern field
if (array_key_exists('custom_attributes__woosea_pattern', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_pattern', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_pattern[' . $loop . ']',
'label' => __(' Pattern', 'woo-product-feed-pro'),
'placeholder' => 'Pattern',
'desc_tip' => 'true',
'description' => __('Enter the product Pattern here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_pattern', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Variation Unit pricing measure field
if (array_key_exists('custom_attributes__woosea_unit_pricing_measure', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_unit_pricing_measure', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_unit_pricing_measure[' . $loop . ']',
'label' => __(' Unit pricing measure', 'woo-product-feed-pro'),
'placeholder' => 'Unit pricing measure',
'desc_tip' => 'true',
'description' => __('Enter the product Unit pricing measure here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_unit_pricing_measure', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Variation Unit pricing base measure field
if (array_key_exists('custom_attributes__woosea_unit_pricing_base_measure', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_unit_pricing_base_measure', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_variable_unit_pricing_base_measure[' . $loop . ']',
'label' => __(' Unit pricing base measure', 'woo-product-feed-pro'),
'placeholder' => 'Unit pricing base measure',
'desc_tip' => 'true',
'description' => __('Enter the product Unit pricing base measure here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_unit_pricing_base_measure', true),
'wrapper_class' => 'form-row-first',
)
);
}
// Variation optimized title field
if (array_key_exists('custom_attributes__woosea_optimized_title', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_optimized_title', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_optimized_title[' . $loop . ']',
'label' => __(' Optimized title', 'woo-product-feed-pro'),
'placeholder' => 'Optimized title',
'desc_tip' => 'true',
'description' => __('Enter a optimized product title here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_optimized_title', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Installment month field
if (array_key_exists('custom_attributes__woosea_installment_months', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_installment_months', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_installment_months[' . $loop . ']',
'label' => __(' Installment months', 'woo-product-feed-pro'),
'placeholder' => 'Installment months',
'desc_tip' => 'true',
'description' => __('Enter the number of montly installments for the buyer here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_installment_months', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Installment amount field
if (array_key_exists('custom_attributes__woosea_installment_amount', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_installment_amount', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_installment_amount[' . $loop . ']',
'label' => __(' Installment amount', 'woo-product-feed-pro'),
'placeholder' => 'Installment amount',
'desc_tip' => 'true',
'description' => __('Enter the installment amount here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_installment_amount', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Add product condition drop-down
if (array_key_exists('custom_attributes__woosea_condition', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_condition', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_condition[' . $loop . ']',
'label' => __('Product condition', 'woo-product-feed-pro'),
'placeholder' => 'Product condition',
'desc_tip' => 'true',
'description' => __('Select the product condition.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_condition', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'new' => __('new', 'woo-product-feed-pro'),
'refurbished' => __('refurbished', 'woo-product-feed-pro'),
'used' => __('used', 'woo-product-feed-pro'),
'damaged' => __('damaged', 'woo-product-feed-pro'),
)
)
);
}
// Add product age_group drop-down
if (array_key_exists('custom_attributes__woosea_age_group', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_age_group', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_age_group[' . $loop . ']',
'label' => __('Product age group', 'woo-product-feed-pro'),
'placeholder' => 'Product age group',
'desc_tip' => 'true',
'description' => __('Select the product age group.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_age_group', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'newborn' => __('newborn', 'woo-product-feed-pro'),
'infant' => __('infant', 'woo-product-feed-pro'),
'toddler' => __('toddler', 'woo-product-feed-pro'),
'kids' => __('kids', 'woo-product-feed-pro'),
'adult' => __('adult', 'woo-product-feed-pro'),
)
)
);
}
// Cost of good sold
if (array_key_exists('custom_attributes__woosea_cost_of_good_sold', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_cost_of_good_sold', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_cost_of_good_sold[' . $loop . ']',
'label' => __(' Cost of good sold', 'woo-product-feed-pro'),
'placeholder' => 'Cost of good sold',
'desc_tip' => 'true',
'description' => __('Enter the cost of good sold.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_cost_of_good_sold', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Multipack
if (array_key_exists('custom_attributes__woosea_multipack', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_multipack', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_multipack[' . $loop . ']',
'label' => __(' Multipack', 'woo-product-feed-pro'),
'placeholder' => 'Multipack amount',
'desc_tip' => 'true',
'description' => __('Enter the multipack amount here.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_multipack', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Is bundle
if (array_key_exists('custom_attributes__woosea_is_bundle', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_is_bundle', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_is_bundle[' . $loop . ']',
'label' => __('Is bundle', 'woo-product-feed-pro'),
'placeholder' => 'Is bundle',
'desc_tip' => 'true',
'description' => __('Select the is bundle value.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_is_bundle', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woocommerce'),
'yes' => __('yes', 'woocommerce'),
'no' => __('no', 'woocommerce'),
)
)
);
}
// Energy efficiency class
if (array_key_exists('custom_attributes__woosea_energy_efficiency_class', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_energy_efficiency_class', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_energy_efficiency_class[' . $loop . ']',
'label' => __('Energy efficiency class', 'woo-product-feed-pro'),
'placeholder' => 'Energy efficiency class',
'desc_tip' => 'true',
'description' => __('Select the energy efficiency class.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_energy_efficiency_class', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'A+++' => __('A+++', 'woo-product-feed-pro'),
'A++' => __('A++', 'woo-product-feed-pro'),
'A+' => __('A+', 'woo-product-feed-pro'),
'A' => __('A', 'woo-product-feed-pro'),
'B' => __('B', 'woo-product-feed-pro'),
'C' => __('C', 'woo-product-feed-pro'),
'D' => __('D', 'woo-product-feed-pro'),
'E' => __('E', 'woo-product-feed-pro'),
'F' => __('F', 'woo-product-feed-pro'),
'G' => __('G', 'woo-product-feed-pro'),
)
)
);
}
// Minimum energy efficiency class
if (array_key_exists('custom_attributes__woosea_min_energy_efficiency_class', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_min_energy_efficiency_class', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_min_energy_efficiency_class[' . $loop . ']',
'label' => __('Minimum energy efficiency class', 'woo-product-feed-pro'),
'placeholder' => 'Minimum energy efficiency class',
'desc_tip' => 'true',
'description' => __('Select the minimum energy efficiency class.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_min_energy_efficiency_class', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'A+++' => __('A+++', 'woo-product-feed-pro'),
'A++' => __('A++', 'woo-product-feed-pro'),
'A+' => __('A+', 'woo-product-feed-pro'),
'A' => __('A', 'woo-product-feed-pro'),
'B' => __('B', 'woo-product-feed-pro'),
'C' => __('C', 'woo-product-feed-pro'),
'D' => __('D', 'woo-product-feed-pro'),
'E' => __('E', 'woo-product-feed-pro'),
'F' => __('F', 'woo-product-feed-pro'),
'G' => __('G', 'woo-product-feed-pro'),
)
)
);
}
// Maximum energy efficiency class
if (array_key_exists('custom_attributes__woosea_max_energy_efficiency_class', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_max_energy_efficiency_class', true))))
{
woocommerce_wp_select(
array(
'id' => '_woosea_max_energy_efficiency_class[' . $loop . ']',
'label' => __('Maximum energy efficiency class', 'woo-product-feed-pro'),
'placeholder' => 'Maximum energy efficiency class',
'desc_tip' => 'true',
'description' => __('Select the maximum energy efficiency class.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_max_energy_efficiency_class', true),
'wrapper_class' => 'form-row form-row-full',
'options' => array(
'' => __('', 'woo-product-feed-pro'),
'A+++' => __('A+++', 'woo-product-feed-pro'),
'A++' => __('A++', 'woo-product-feed-pro'),
'A+' => __('A+', 'woo-product-feed-pro'),
'A' => __('A', 'woo-product-feed-pro'),
'B' => __('B', 'woo-product-feed-pro'),
'C' => __('C', 'woo-product-feed-pro'),
'D' => __('D', 'woo-product-feed-pro'),
'E' => __('E', 'woo-product-feed-pro'),
'F' => __('F', 'woo-product-feed-pro'),
'G' => __('G', 'woo-product-feed-pro'),
)
)
);
}
// Is promotion
if (array_key_exists('custom_attributes__woosea_is_promotion', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_is_promotion', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_is_promotion[' . $loop . ']',
'label' => __(' Is promotion', 'woo-product-feed-pro'),
'placeholder' => 'Is promotion',
'desc_tip' => 'true',
'description' => __('Enter your promotion ID', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_is_promotion', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Custom field 0
if (array_key_exists('custom_attributes__woosea_custom_field_0', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_custom_field_0', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_0[' . $loop . ']',
'label' => __(' Custom field 0', 'woo-product-feed-pro'),
'placeholder' => 'Custom field 0',
'desc_tip' => 'true',
'description' => __('Enter your custom field 0', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_custom_field_0', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Custom field 1
if (array_key_exists('custom_attributes__woosea_custom_field_1', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_custom_field_1', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_1[' . $loop . ']',
'label' => __(' Custom field 1', 'woo-product-feed-pro'),
'placeholder' => 'Custom field 1',
'desc_tip' => 'true',
'description' => __('Enter your custom field 1', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_custom_field_1', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Custom field 2
if (array_key_exists('custom_attributes__woosea_custom_field_2', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_custom_field_2', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_2[' . $loop . ']',
'label' => __(' Custom field 2', 'woo-product-feed-pro'),
'placeholder' => 'Custom field 2',
'desc_tip' => 'true',
'description' => __('Enter your custom field 2', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_custom_field_2', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Custom field 3
if (array_key_exists('custom_attributes__woosea_custom_field_3', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_custom_field_3', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_3[' . $loop . ']',
'label' => __(' Custom field 3', 'woo-product-feed-pro'),
'placeholder' => 'Custom field 3',
'desc_tip' => 'true',
'description' => __('Enter your custom field 3', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_custom_field_3', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Custom field 4
if (array_key_exists('custom_attributes__woosea_custom_field_4', $extra_attributes) or (!empty(get_post_meta($variation->ID, '_woosea_custom_field_4', true))))
{
woocommerce_wp_text_input(
array(
'id' => '_woosea_custom_field_4[' . $loop . ']',
'label' => __(' Custom field 4', 'woocommerce'),
'placeholder' => 'Custom field 4',
'desc_tip' => 'true',
'description' => __('Enter your custom field 4', 'woocommerce'),
'value' => get_post_meta($variation->ID, '_woosea_custom_field_4', true),
'wrapper_class' => 'form-row-last',
)
);
}
// Exclude product from feed
woocommerce_wp_checkbox(
array(
'id' => '_woosea_exclude_product[' . $loop . ']',
'label' => __(' Exclude from feeds', 'woo-product-feed-pro'),
'placeholder' => 'Exclude from feeds',
'desc_tip' => 'true',
'description' => __('Check this box if you want this product to be excluded from product feeds.', 'woo-product-feed-pro'),
'value' => get_post_meta($variation->ID, '_woosea_exclude_product', true),
)
);
}
}
add_action('woocommerce_product_after_variable_attributes', 'woosea_custom_variable_fields', 10, 3);
/**
* Save the unique identifier fields for variation products
*/
function woosea_save_custom_variable_fields($post_id)
{
if (isset($_POST['variable_sku']))
{
$variable_sku = sanitize_text_field($_POST['variable_sku']);
$variable_post_id = sanitize_text_field($_POST['variable_post_id']);
if (is_array($variable_post_id))
{
$max_loop = max(array_keys($variable_post_id));
}
else
{
$max_loop = 0;
}
for ($i = 0; $i <= $max_loop; $i++)
{
if (!isset($variable_post_id[$i]))
{
continue;
}
// Brand Field
if (isset($_POST['_woosea_variable_brand']))
{
$_brand = sanitize_text_field($_POST['_woosea_variable_brand']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_brand[$i]))
{
update_post_meta($variation_id, '_woosea_brand', stripslashes(sanitize_text_field($_brand[$i])));
}
}
// MPN Field
if (isset($_POST['_woosea_variable_mpn']))
{
$_mpn = sanitize_text_field($_POST['_woosea_variable_mpn']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_mpn[$i]))
{
update_post_meta($variation_id, '_woosea_mpn', stripslashes(sanitize_text_field($_mpn[$i])));
}
}
// UPC Field
if (isset($_POST['_woosea_variable_upc']))
{
$_upc = sanitize_text_field($_POST['_woosea_variable_upc']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_upc[$i]))
{
update_post_meta($variation_id, '_woosea_upc', stripslashes(sanitize_text_field($_upc[$i])));
}
}
// EAN Field
if (isset($_POST['_woosea_variable_ean']))
{
$_ean = sanitize_text_field($_POST['_woosea_variable_ean']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_ean[$i]))
{
update_post_meta($variation_id, '_woosea_ean', stripslashes(sanitize_text_field($_ean[$i])));
}
}
// GTIN Field
if (isset($_POST['_woosea_variable_gtin']))
{
$_gtin = sanitize_text_field($_POST['_woosea_variable_gtin']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_gtin[$i]))
{
update_post_meta($variation_id, '_woosea_gtin', stripslashes(sanitize_text_field($_gtin[$i])));
}
}
// Color Field
if (isset($_POST['_woosea_variable_color']))
{
$_color = sanitize_text_field($_POST['_woosea_variable_color']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_color[$i]))
{
update_post_meta($variation_id, '_woosea_color', stripslashes(sanitize_text_field($_color[$i])));
}
}
// Size Field
if (isset($_POST['_woosea_variable_size']))
{
$_size = sanitize_text_field($_POST['_woosea_variable_size']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_size[$i]))
{
update_post_meta($variation_id, '_woosea_size', stripslashes(sanitize_text_field($_size[$i])));
}
}
// Gender Field
if (isset($_POST['_woosea_variable_gender']))
{
$_gender = sanitize_text_field($_POST['_woosea_variable_gender']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_gender[$i]))
{
update_post_meta($variation_id, '_woosea_gender', stripslashes(sanitize_text_field($_gender[$i])));
}
}
// Material Field
if (isset($_POST['_woosea_variable_material']))
{
$_material = sanitize_text_field($_POST['_woosea_variable_material']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_material[$i]))
{
update_post_meta($variation_id, '_woosea_material', stripslashes(sanitize_text_field($_material[$i])));
}
}
// Pattern Field
if (isset($_POST['_woosea_variable_pattern']))
{
$_pattern = sanitize_text_field($_POST['_woosea_variable_pattern']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_pattern[$i]))
{
update_post_meta($variation_id, '_woosea_pattern', stripslashes(sanitize_text_field($_pattern[$i])));
}
}
// Unit pricing measure Field
if (isset($_POST['_woosea_variable_unit_pricing_measure']))
{
$_pricing_measure = sanitize_text_field($_POST['_woosea_variable_unit_pricing_measure']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_pricing_measure[$i]))
{
update_post_meta($variation_id, '_woosea_unit_pricing_measure', stripslashes(sanitize_text_field($_pricing_measure[$i])));
}
}
// Unit pricing base measure Field
if (isset($_POST['_woosea_variable_unit_pricing_base_measure']))
{
$_pricing_base = sanitize_text_field($_POST['_woosea_variable_unit_pricing_base_measure']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_pricing_base[$i]))
{
update_post_meta($variation_id, '_woosea_unit_pricing_base_measure', stripslashes(sanitize_text_field($_pricing_base[$i])));
}
}
// Optimized title Field
if (isset($_POST['_woosea_optimized_title']))
{
$_opttitle = sanitize_text_field($_POST['_woosea_optimized_title']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_opttitle[$i]))
{
update_post_meta($variation_id, '_woosea_optimized_title', stripslashes(sanitize_text_field($_opttitle[$i])));
}
}
// Installment months Field
if (isset($_POST['_woosea_installment_months']))
{
$_installment_months = sanitize_text_field($_POST['_woosea_installment_months']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_installment_months[$i]))
{
update_post_meta($variation_id, '_woosea_installment_months', stripslashes(sanitize_text_field($_installment_months[$i])));
}
}
// Installment amount Field
if (isset($_POST['_woosea_installment_amount']))
{
$_installment_amount = sanitize_text_field($_POST['_woosea_installment_amount']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_installment_amount[$i]))
{
update_post_meta($variation_id, '_woosea_installment_amount', stripslashes(sanitize_text_field($_installment_amount[$i])));
}
}
// Product condition Field
if (isset($_POST['_woosea_condition']))
{
$_condition = sanitize_text_field($_POST['_woosea_condition']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_condition[$i]))
{
update_post_meta($variation_id, '_woosea_condition', stripslashes(sanitize_text_field($_condition[$i])));
}
}
// Product age group
if (isset($_POST['_woosea_age_group']))
{
$_age_group = sanitize_text_field($_POST['_woosea_age_group']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_age_group[$i]))
{
update_post_meta($variation_id, '_woosea_age_group', stripslashes(sanitize_text_field($_age_group[$i])));
}
}
// Cost of good sold
if (isset($_POST['_woosea_cost_of_good_sold']))
{
$_cost_of_good_sold = sanitize_text_field($_POST['_woosea_cost_of_good_sold']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_cost_of_good_sold[$i]))
{
update_post_meta($variation_id, '_woosea_cost_of_good_sold', stripslashes(sanitize_text_field($_cost_of_good_sold[$i])));
}
}
// Multipack
if (isset($_POST['_woosea_multipack']))
{
$_multipack = sanitize_text_field($_POST['_woosea_multipack']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_multipack[$i]))
{
update_post_meta($variation_id, '_woosea_multipack', stripslashes(sanitize_text_field($_multipack[$i])));
}
}
// Is promotion
if (isset($_POST['_woosea_is_promotion']))
{
$_is_promotion = sanitize_text_field($_POST['_woosea_is_promotion']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_is_promotion[$i]))
{
update_post_meta($variation_id, '_woosea_is_promotion', stripslashes(sanitize_text_field($_is_promotion[$i])));
}
}
// Is bundle
if (isset($_POST['_woosea_is_bundle']))
{
$_is_bundle = sanitize_text_field($_POST['_woosea_is_bundle']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_is_bundle[$i]))
{
update_post_meta($variation_id, '_woosea_is_bundle', stripslashes(sanitize_text_field($_is_bundle[$i])));
}
}
// Energy efficiency class
if (isset($_POST['_woosea_energy_efficiency_class']))
{
$_energy_efficiency_class = sanitize_text_field($_POST['_woosea_energy_efficiency_class']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_energy_efficiency_class[$i]))
{
update_post_meta($variation_id, '_woosea_energy_efficiency_class', stripslashes(sanitize_text_field($_energy_efficiency_class[$i])));
}
}
// Minimum energy efficiency class
if (isset($_POST['_woosea_min_energy_efficiency_class']))
{
$_min_energy_efficiency_class = sanitize_text_field($_POST['_woosea_min_energy_efficiency_class']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_min_energy_efficiency_class[$i]))
{
update_post_meta($variation_id, '_woosea_min_energy_efficiency_class', stripslashes(sanitize_text_field($_min_energy_efficiency_class[$i])));
}
}
// Maximum energy efficiency class
if (isset($_POST['_woosea_max_energy_efficiency_class']))
{
$_max_energy_efficiency_class = sanitize_text_field($_POST['_woosea_max_energy_efficiency_class']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_max_energy_efficiency_class[$i]))
{
update_post_meta($variation_id, '_woosea_max_energy_efficiency_class', stripslashes(sanitize_text_field($_max_energy_efficiency_class[$i])));
}
}
// Custom field 0
if (isset($_POST['_woosea_custom_field_0']))
{
$_custom_field_0 = sanitize_text_field($_POST['_woosea_custom_field_0']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_custom_field_0[$i]))
{
update_post_meta($variation_id, '_woosea_custom_field_0', stripslashes(sanitize_text_field($_custom_field_0[$i])));
}
}
// Custom field 1
if (isset($_POST['_woosea_custom_field_1']))
{
$_custom_field_1 = sanitize_text_field($_POST['_woosea_custom_field_1']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_custom_field_1[$i]))
{
update_post_meta($variation_id, '_woosea_custom_field_1', stripslashes(sanitize_text_field($_custom_field_1[$i])));
}
}
// Custom field 2
if (isset($_POST['_woosea_custom_field_2']))
{
$_custom_field_2 = sanitize_text_field($_POST['_woosea_custom_field_2']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_custom_field_2[$i]))
{
update_post_meta($variation_id, '_woosea_custom_field_2', stripslashes(sanitize_text_field($_custom_field_2[$i])));
}
}
// Custom field 3
if (isset($_POST['_woosea_custom_field_3']))
{
$_custom_field_3 = sanitize_text_field($_POST['_woosea_custom_field_3']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_custom_field_3[$i]))
{
update_post_meta($variation_id, '_woosea_custom_field_3', stripslashes(sanitize_text_field($_custom_field_3[$i])));
}
}
// Custom field 4
if (isset($_POST['_woosea_custom_field_4']))
{
$_custom_field_4 = sanitize_text_field($_POST['_woosea_custom_field_4']);
$variation_id = (int) $variable_post_id[$i];
if (!empty($_custom_field_4[$i]))
{
update_post_meta($variation_id, '_woosea_custom_field_4', stripslashes(sanitize_text_field($_custom_field_4[$i])));
}
}
// Exclude product from feed
if (empty($_POST['_woosea_exclude_product']))
{
$_excludeproduct[$i] = "no";
}
else
{
$_excludeproduct = sanitize_text_field($_POST['_woosea_exclude_product']);
}
$variation_id = (int) $variable_post_id[$i];
if (!empty($_excludeproduct[$i]))
{
update_post_meta($variation_id, '_woosea_exclude_product', stripslashes($_excludeproduct[$i]));
}
}
}
}
add_action('woocommerce_save_product_variation', 'woosea_save_custom_variable_fields', 10, 1);
/**
* Set project history: amount of products in the feed
**/
function woosea_update_project_history($project_hash)
{
$feed_config = get_option('cron_projects');
foreach ($feed_config as $key => $project)
{
if ($project['project_hash'] == $project_hash)
{
$nr_products = 0;
$upload_dir = wp_upload_dir();
$base = $upload_dir['basedir'];
$path = $base . "/woo-product-feed-pro/" . $project['fileformat'];
$file = $path . "/" . sanitize_file_name($project['filename']) . "." . $project['fileformat'];
if (file_exists($file))
{
if (($project['fileformat'] == "csv") || ($project['fileformat'] == "txt"))
{
$fp = file($file);
$raw_nr_products = count($fp);
$nr_products = $raw_nr_products - 1; // header row of csv
}
else
{
$xml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($project['name'] == "Yandex")
{
if (isset($xml->offers->offer))
{
$nr_products = count($xml->offers->offer);
}
}
else
{
if ($project['taxonomy'] == "none")
{
$nr_products = count($xml->product);
}
else
{
$nr_products = count($xml->channel->item);
}
}
}
}
$count_timestamp = date("d M Y H:i");
$number_run = array(
$count_timestamp => $nr_products,
);
$feed_config = get_option('cron_projects');
foreach ($feed_config as $key => $val)
{
if (($val['project_hash'] == $project['project_hash']) and ($val['running'] == "ready"))
{
//unset($feed_config[$key]['history_products']);
if (array_key_exists('history_products', $feed_config[$key]))
{
$feed_config[$key]['history_products'][$count_timestamp] = $nr_products;
}
else
{
$feed_config[$key]['history_products'] = $number_run;
}
}
}
update_option('cron_projects', $feed_config);
}
}
}
add_action('woosea_update_project_stats', 'woosea_update_project_history', 1, 1);
/**
* Get the attribute mapping helptexts
*/
function woosea_fieldmapping_dialog_helptext()
{
$field = sanitize_text_field($_POST['field']);
switch ($field)
{
case "g:id";
$helptext = "(Required field) The g:id field is used to uniquely identify each product. The g:id needs to be unique and remain the same forever. Google advises to map the g:id field to a SKU value, however since this field is not always present nor always filled we suggest you map the 'Product Id' field to g:id.";
break;
case "g:title";
$helptext = "(Required field) The g:title field should clearly identify the product you are selling. We suggest you map this field to your 'Product name'.";
break;
case "g:description";
$helptext = "(Required field) The g:description field should tell users about your product. We suggest you map this field to your 'Product description' or 'Product short description'";
break;
case "g:link";
$helptext = "(Required field) The g:link field should be filled with the landing page on your website. We suggest you map this field to your 'Link' attribute.";
break;
case "g:image_link";
$helptext = "(Required field) Include the URL for your main product image with the g:image_link attribute. We suggest you map this field to your 'Main image' attribute.";
break;
case "g:definition";
$helptext = "(Required field) Use the g:availability attribute to tell users and Google whether you have a product in stock. We suggest you map this field to your 'Availability' attribute.";
break;
case "g:price";
$helptext = "(Required field) Use the g:price attribute to tell users how much you are charging for your product. We suggest you map this field to your 'Price' attribute. When a product is on sale the plugin will automatically get the sale price instead of the normal base price. Also, make sure you use a currency pre- or suffix as this is required by Google when you have not configured a currency in your Google Merchant center. The plugin automatically determines your relevant currency and puts this in the price prefix field.";
break;
case "g:google_product_category";
$helptext = "(Required for some product categories) Use the g:google_product_category attribute to indicate the category of your item based on the Google product taxonomy. Map this field to your 'Category' attribute. In the next configuration step you will be able to map your categories to Google's category taxonomy. Categorizing your product helps ensure that your ad is shown with the right search results.";
break;
case "g:brand";
$helptext = "Use the g:brand attribute to indicate the product's brand name. The brand is used to help identify your product and will be shown to users who view your ad. g:brand is required for each product with a clearly associated brand or manufacturer. If the product doesn't have a clearly associated brand (e.g. movies, books, music) or is a custom-made product (e.g. art, custom t-shirts, novelty products and handmade products), the attribute is optional. As WooCommerce does not have a brand attribute out of the box you will probably have to map the g:brand field to a custom/dynamic field or product attribute.";
break;
case "g:gtin";
$helptext = "(Required for all products with a GTIN assigned by the manufacturer). This specific number helps Google to make your ad richer and easier for users to find. Products submitted without any unique product identifiers are difficult to classify and may not be able to take advantage of all Google Shopping features. Several different types of ID numbers are considered a GTIN, for example: EAN, UPC, JAN, ISBN, IFT-14. Most likely you have configured custom/dynamic or product attribute that you need to map to the g:gtin field.";
break;
case "g:mpn";
$helptext = "(Required for all products without a manufacturer-assigned GTIN.) USe the mpn attribute to submit your product's Manufacturer Part Number (MPN). MPNs are used to uniquely identify a specific product among all products from the same manufacturer. Users might search Google Shopping specifically for an MPN, so providing the MPN can help ensure that your product is shown in relevant situations. When a product doesn't have a clearly associated mpn or is a custom-made product (e.g. art, custom t-shirts, novelty products and handmade products), the attribute is optional.";
break;
case "g:identifier_exists";
$helptext = "(Required only for new products that don’t have gtin and brand or mpn and brand.) Use the g:identifier_exists attribute to indicate that unique product identifiers aren’t available for your product. Unique product identifiers include gtin, mpn, and brand. The plugin automatically determines if the value for a product is 'no' or 'yes' when you set the g:identifier_exists to 'Plugin calculation'.";
break;
case "g:condition";
$helptext = "(Required) Tell users about the condition of the product you are selling. Supported values are: 'new', 'refurbished' and 'used'. We suggest you map this field to the 'Condition' attribute.";
break;
case "g:item_group_id";
$helptext = "(Required for the following countries: Brazil, France, Germany, Japan, United Kingdom and the United States). The g:item_group_id is used to group product variants in your product data. We suggest you map the g:item_group_id to the 'Item group ID' attribute. The plugin automatically ads the correct value to this field and makes sure the 'mother' products is not in your product feed (as required by Google).";
break;
case "g:shipping";
$helptext = "(Required when you need to override the shipping settings that you set up in Merchant Center) Google recommends that you set up shipping costs through your Merchant center. However, when you need to override these settings you can map the g:shipping field to the 'Shipping price' attribute.";
break;
case "Structured data fix";
$helptext = "Because of a bug in WooCommerce variable products will get disapproved in Google's Merchant Center. WooCommerce adds the price of the cheapest variable product in the structured data for all variations of a product. Because of this there will be a mismatch between the product price you provide to Google in your Google Shopping product feed and the structured data price on the product landingpage. Google will therefor disapprove the product in its merchant center. You won't be able to advertise on that product in your Google Shopping campaign. Enable this option will fix the structured data on variable product pages by adding the correct variable product price in the JSON-LD structured data so Google will approve the variable products you submitted.";
break;
case "Unique identifiers";
$helptext = "In order to optimise your product feed for Google Shopping and meet all Google's Merchant Center requirements you need to add extra fields / attributes to your products that are not part of WooCommerce by default. Enable this option to get Brand, GTIN, MPN, UPC, EAN, Product condition and optimised title fields";
break;
default:
$helptext = "need information about this field? reach out to support@adtribes.io";
}
$data = array(
'helptext' => $helptext,
);
echo json_encode($data);
wp_die();
}
add_action('wp_ajax_woosea_fieldmapping_dialog_helptext', 'woosea_fieldmapping_dialog_helptext');
/**
* Get the dropdowns for the fieldmapping page
*/
function woosea_fieldmapping_dropdown()
{
check_ajax_referer('woosea_ajax_nonce', 'security');
$user = wp_get_current_user();
$allowed_roles = array('administrator');
if (array_intersect($allowed_roles, $user->roles))
{
$channel_hash = sanitize_text_field($_POST['channel_hash']);
$rowCount = absint(esc_attr(sanitize_text_field($_POST['rowCount'])));
$channel_data = WooSEA_Update_Project::get_channel_data($channel_hash);
require plugin_dir_path(__FILE__) . '/classes/channels/class-' . $channel_data['fields'] . '.php';
$obj = "WooSEA_" . $channel_data['fields'];
$fields_obj = new $obj;
$attributes = $fields_obj->get_channel_attributes();
$field_options = "";
foreach ($attributes as $key => $value)
{
$field_options .= "";
$field_options .= "