....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 217.79.180.202  /  Your IP : 216.73.216.252
Web Server : Apache
System : Linux vps2460721.fastwebserver.de 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64
User : tecnoelite ( 1001)
PHP Version : 8.1.2-1ubuntu2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/tecnoelite/public_html/wp-content/plugins/woomelly/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/tecnoelite/public_html/wp-content/plugins/woomelly/includes/class-wmnotification.php
<?php

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

class WMNotification {

	public static function init() {
		add_action( 'woomelly_notification_orders', array( __CLASS__, 'woomelly_notification_orders' ), 10, 4 );
		add_action( 'woomelly_notification_qandas', array( __CLASS__, 'woomelly_notification_qandas' ), 10, 2 );
	}

	/*public static function get_woomelly_last_resource () {
		$woomelly_notification = get_option( '_wm_notification_last_resource' );
		return $woomelly_notification;
	}
	public static function get_woomelly_last_notification () {
		$woomelly_notification = get_option( '_wm_notification_last_notification' );
		return $woomelly_notification;
	}
	public static function set_woomelly_last_resource ( $value ) {
		$value = trim($value);
		update_option( '_wm_notification_last_resource', $value );
	}
	public static function set_woomelly_last_notification ( $value ) {
		$value = trim($value);
		update_option( '_wm_notification_last_notification', $value );
	}*/

	/**
	 * @return
	 */
	public static function woomelly_notification_orders ( $resource, $data_resource = null, $wm_settings_page = null, $force = false ) {
		$order 								= null;
		$data_review 						= null;
		$woocommerce_status 				= '';
		$woocommerce_currency_id 			= '';
		$wm_payment_id 						= '';
		$notes 								= '';
		$wm_shipping_status 				= '';
		$shipping_option_name 				= '';
		$shipping_mode 						= '';
		$address_1 							= '';
		$postcode 							= '';
		$city 								= '';
		$state 								= '';
		$street_name 						= '';
		$street_number 						= '';
		$comment_ref 						= '';
		$receiver_name 						= '';
		$neighborhood 						= '';		
		$all_products_is_ok 				= false;
		$list_woo_products 					= array();
		$list_woo_products_reviews 			= array();
		$data_notes 						= array();
		$tags 								= wm_get_tags_available('extension');
		$wm_woo_product 					= false;
		$wm_woo_list_products 				= array();
		$is_wc_bundle 						= false;
		$data_shipping 						= null;
		$is_me_full 						= false;
		$it_will_replicate 					= true;
		$it_will_reduce_stock 				= true;
		$is_cart_order 						= false;
		$wm_replicate_order 				= true;
		$meli_category_id 					= "";
		$manufacturing_ending_date 			= "";
		$meli_billing_info 					= "";
		$meli_doc_type 						= "";
		$total_shipping 					= 0;
		$meli_billing_info_request 			= null;

		if ( is_plugin_active('woo-product-bundle/wpc-product-bundles.php') || is_plugin_active('woo-product-bundle-premium/wpc-product-bundles.php') ) {
			$wm_woo_product = true;
		} else if ( is_plugin_active('woocommerce-product-bundles/woocommerce-product-bundles.php') ) {
			$is_wc_bundle = true;
		}

		// comments:null
		// status_detail:{code,description}
		// hidden_for_seller:false
		// mediations:array
		// order_request:{change,return}
		// pickup_id
		// taxes
		// coupon
		if ( $wm_settings_page == null ) $wm_settings_page = new WMSettings();
		$woomelly_alive = Woomelly()->woomelly_is_connect( $wm_settings_page );
		if ( $woomelly_alive ) {
			$settings_extensions = $wm_settings_page->get_settings_extensions();
			if ( $settings_extensions['feedback'] || $settings_extensions['order'] || $wm_settings_page->get_settings_mlw_reduce_stock() == true ) {
				if ( $data_resource == null || !isset($data_resource->buyer) || !isset($data_resource->buyer->first_name) ) {
					$data_resource = WMeli::get_resource( $resource, $wm_settings_page );
				}
				if ( is_object($data_resource) ) {
					if ( isset($data_resource->manufacturing_ending_date) ) {
						$manufacturing_ending_date = $data_resource->manufacturing_ending_date;
					}					
					if ( isset($data_resource->pack_id) && !is_null($data_resource->pack_id) && $data_resource->pack_id != "" ) {
						$is_cart_order = true;
					}
					if ( get_transient( '_woomelly_opl_' . $data_resource->id ) === true && $is_cart_order == true ) {
						$wm_replicate_order = false;
					}
					if ( $wm_replicate_order == true ) {
						$code = $data_resource->id;
						$woocommerce_currency_id = apply_filters('woomelly_set_meli_currency_id_order', $data_resource->currency_id, $data_resource, $wm_settings_page );
						if ( is_object($data_resource->shipping) && isset($data_resource->shipping->id) && $data_resource->shipping->id != null && $data_resource->shipping->id != "" ) {
						    $data_shipping = WMeli::get_shipping( $data_resource->shipping->id, $wm_settings_page );
						    if ( is_object($data_shipping) ) {
						        if ( isset($data_shipping->logistic_type) && $data_shipping->logistic_type == "fulfillment" ) {
						        	$is_me_full = true;
									if ( $wm_settings_page->get_settings_me_full_stock() != "omit_trash" ) {
										$it_will_replicate = true;
									} else {
										$it_will_replicate = false;
									}
						        }
						    } else {
						    	unset( $data_shipping );
						    	$data_shipping = null;
						    }
						}
						$wm_replicate_order = apply_filters( 'woomelly_notification_orders_replicate', $it_will_replicate, $data_resource, $data_shipping, $wm_settings_page );
						if ( $wm_replicate_order == true && $force !== 4 && $force !== 5 ) {
							//WMlog::set_log( 'YES: replicate orders - ' . $data_resource->id, 'error' );							
							if ( $is_me_full == true ) {
								if ( $wm_settings_page->get_settings_me_full_stock() == "import_ds" ) {
									$it_will_reduce_stock = true;
								} else {
									$it_will_reduce_stock = false;
								}
							}
							if ( $settings_extensions['order'] != true ) {
								if ( $wm_settings_page->get_settings_mlw_reduce_stock() == true && $it_will_reduce_stock == true ) {
									if ( $data_resource->status != 'invalid' ) {
										$date_created = strtotime( $data_resource->date_created );
										if ( $date_created >= $wm_settings_page->get_settings_datetime_order() || $wm_settings_page->get_settings_datetime_order() == "" ) {
											if ( !empty($data_resource->order_items) ) {
												foreach ( $data_resource->order_items as $value ) {
													$wm_product = null;
													$woo_product = null;
													if ( isset($value->item->variation_id) && $value->item->variation_id!="" ) {
														$wm_product = wm_get_product_by_code( $value->item->variation_id, false );
														if ( $wm_product == null ) {
															$wm_product = wm_get_product_by_code( $value->item->id );
														}
													} else {
														$wm_product = wm_get_product_by_code( $value->item->id );
													}
													if ( $wm_product != null ) {
														$woo_product = wc_get_product( $wm_product->get_id() );
														if ( is_object($woo_product) && $woo_product->get_status() != "trash" ) {
															$meli_order_exist = true;
															$meli_order_operation = 'decrease';
															if ( $data_resource->status != 'cancelled' ) {
																if ( ! in_array($data_resource->id, $wm_product->get_woomelly_orders() ) ) {
																	$meli_order_exist = false;
																}
															} else {
																if ( ! in_array($data_resource->id, $wm_product->get_woomelly_orders_cancelled() ) ) {
																	$meli_order_exist = false;
																	$meli_order_operation = 'increase';
																}
															}
															if ( $meli_order_exist == false ) {
																//if ( $data_resource->status != 'cancelled' ) {
																	$value_quantity = intval($value->quantity);
																	if ( apply_filters( 'woomelly_enable_decrease_stock_extsales_inactive', false ) == true ) {
																		$data_item_stock = WMeli::get_item( $value->item->id, false, null, null, $wm_settings_page );
																		if ( is_object($data_item_stock) ) {
																			if ( isset($value->item->variation_id) && $value->item->variation_id!="" && !empty($data_item_stock->variations) ) {
																				$wm_aux_break = false;
																				foreach ( $data_item_stock->variations as $meli_variation ) {
																					if ( $wm_aux_break == false ) {
																						if ( $meli_variation->id == $value->item->variation_id ) {
																							$value_quantity = $meli_variation->available_quantity;
																							$meli_order_operation = 'set';
																							$wm_aux_break = true;
																						}
																					}
																				}
																			} else {
																				$value_quantity = $data_item_stock->available_quantity;
																				$meli_order_operation = 'set';
																			}
																		}
																	}
																	wm_reduce_productwoo_stock( $woo_product, $value_quantity, null, $meli_order_operation );
																//bundle
																	if ( $wm_woo_product == true ) {
																		$woosb_arr = array();
																		$woosb_ids = wm_get_meta_data( $wm_product->get_id(), 'woosb_ids', true );
																		//$woosb_ids = get_post_meta( $wm_product->get_id(), 'woosb_ids', true );
																		if ( $woosb_ids && $woosb_ids != "" && !is_array($woosb_ids) ) {
																			$woosb_items = explode( ',', $woosb_ids );
																			if ( is_array( $woosb_items ) && count( $woosb_items ) > 0 ) {
																				foreach ( $woosb_items as $woosb_item ) {
																					if ( !is_array($woosb_item) ) {
																						$woosb_item_arr = explode( '/', $woosb_item );
																						$woosb_arr[]    = array(
																							'id'  => intval( isset( $woosb_item_arr[0] ) ? $woosb_item_arr[0] : 0 ),
																							'qty' => intval( isset( $woosb_item_arr[1] ) ? $woosb_item_arr[1] : 1 )
																						);
																					}
																				}
																				if ( !empty($woosb_arr) ) {
																					foreach ( $woosb_arr as $value_woosb ) {
																						if ( intval($value_woosb['id']) > 0 ) {
																							$woosb_product_temp = wc_get_product( $value_woosb['id'] );
																							if ( is_object($woosb_product_temp) ) {
																								$value_woosb_qty = $value_quantity * $value_woosb['qty'];
																								wm_reduce_productwoo_stock( $woosb_product_temp, $value_woosb_qty, null, $meli_order_operation );
																								if ( $meli_order_operation == 'decrease' || $meli_order_operation == 'set' ) {
																									wm_reduce_productwoo_bundle_stock( $woosb_product_temp, $wm_settings_page );
																								}
																							}
																							unset( $woosb_product_temp );
																						}
																					}
																				}
																			}
																		}
																	} else if ( $is_wc_bundle == true ) {
																		$product_line_item = wc_get_product( $wm_product->get_id() );
																		if ( is_object($product_line_item) && $product_line_item->get_type() == 'bundle' ) {
																			$bundled_items = $product_line_item->get_bundled_items();
																			if ( !empty($bundled_items) ) {
																				foreach ( $bundled_items as $bundled_item ) {
																					$value_woosb_qty = $value_quantity * $bundled_item->get_quantity();
																					$woosb_product_temp = $bundled_item->product;
																					wm_reduce_productwoo_stock( $woosb_product_temp, $value_woosb_qty, null, $meli_order_operation );
																					if ( $meli_order_operation == 'decrease' || $meli_order_operation == 'set' ) {
																						wm_reduce_productwoo_bundle_stock( $woosb_product_temp, $wm_settings_page );
																					}
																					unset( $woosb_product_temp );
																				}
																			}
																		}
																	}
																//bundle
																if ( $data_resource->status != 'cancelled' ) {
																	$wm_product->set_woomelly_order($data_resource->id);
																} else {
																	$wm_product->set_woomelly_order_cancelled($data_resource->id);
																}
															}
														}
													}
													unset( $wm_product );
													unset( $woo_product );
												}
											} else {
												// The Mercado Libre order did not register items
											}
										} else {
											// WMlog::set_log( $date_created, 'error' );
										}
									} else {
										// Invalid orders are not replicated
									}
								} else {
									// The individual module to reduce inventory by sale of Mercado Libre is not active
								}
							} else {
								$date_created = strtotime( $data_resource->date_created );
								if ( $date_created >= $wm_settings_page->get_settings_datetime_order() ) {
									switch ( $data_resource->status ) {
										case 'confirmed': //estado inicial de un orden; aún sin haber sido pagada.
											$woocommerce_status = apply_filters('wm_filter_wc_status_on_hold', 'on-hold');
											break;
										case 'payment_required': //necesario se confirme pago para ver info del usuario
											$woocommerce_status = apply_filters('wm_filter_wc_status_pending', 'pending');
											break;
										case 'payment_in_process': //existe pago pero no acreditado
											$woocommerce_status = apply_filters('wm_filter_wc_status_pending', 'pending');
											break;
										case 'partially_paid': //existe pago acreditado pero aun no es suficiente
											$woocommerce_status = apply_filters('wm_filter_wc_status_pending', 'pending');
											break;
										case 'paid': //pagada
											$woocommerce_status = apply_filters('wm_filter_wc_status_processing', 'processing');
											break;
										case 'cancelled': //por alguna razon no concreto la orden
											$woocommerce_status = apply_filters('wm_filter_wc_status_cancelled', 'cancelled');
											break;
										case 'pending_cancel': //se quiere cancelar la orden pero cuesta devolver el pago (ML)
											$woocommerce_status = apply_filters('wm_filter_wc_status_cancelled', 'cancelled');
											break;
										case 'invalid': //se invalido porque venia de un comprador malicioso
											$woocommerce_status = apply_filters('wm_filter_wc_status_failed', 'failed');
											break;
									}
									if ( !empty($data_resource->order_items) ) {
										foreach ( $data_resource->order_items as $value ) {
											$wm_product = null;
											$woo_product = null;
											if ( isset($value->item->variation_id) && $value->item->variation_id!="" ) {
												$wm_product = wm_get_product_by_code( $value->item->variation_id, false );
												if ( $wm_product == null ) {
													$wm_product = wm_get_product_by_code( $value->item->id, false );
												}
											} else {
												$wm_product = wm_get_product_by_code( $value->item->id );
											}
											if ( $wm_product != null ) {
												$woo_product = wc_get_product( $wm_product->get_id() );
												if ( is_object($woo_product) && $woo_product->get_status() != "trash" ) {
													$list_woo_products[] = $woo_product;
													$all_products_is_ok = true;
												} else {
													$all_products_is_ok = false;
													break;								
												}
											} else {
												$all_products_is_ok = false;
												break;
											}
											unset( $wm_product );
											unset( $woo_product );
										}
									}
									if ( $all_products_is_ok == true && !empty($list_woo_products) ) {
										if ( !isset($data_resource->buyer) || !isset($data_resource->buyer->first_name) ) {
											unset( $data_resource );
											$data_resource = WMeli::get_resource( $resource, $wm_settings_page );
										}
										if ( is_object($data_resource) ) {
											$code = $data_resource->id;
											$tags = wm_fill_order_tags( $tags, $data_resource, $resource, $wm_settings_page );										
											$wm_order = wm_get_order_by_code( $code, $data_resource );
											if ( is_object($wm_order) ) {
												$woomelly_continue_by_cart = false;
												if ( $is_cart_order == true && !in_array($data_resource->id, $wm_order->get_woomelly_code_order_cart()) ) {
													$woomelly_continue_by_cart = true;
												}
												if ( $wm_order->validate_last_updated( $data_resource, $data_shipping ) == true || $woomelly_continue_by_cart == true || $force === true ) {
													if ( $wm_order->get_woomelly_sync_status_field() ) {
														$order = wc_get_order( $wm_order->get_id() );
														if ( is_object($order) && $order->get_status() != "trash" ) {
															if ( is_object($data_shipping) && isset($data_shipping->logistic_type) ) {
																$wm_order->set_woomelly_shipping_logistic_type( $data_shipping->logistic_type );
															}
															$data_resource_tags = array();
															if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
																$data_resource_tags = $data_resource->tags;
															}
															$wm_order->set_woomelly_tags( $data_resource_tags );
															unset( $data_resource_tags );
															$wm_order->set_woomelly_manufacturing_ending_date( $manufacturing_ending_date );
															$wm_buyer_email_aux = "";
															if ( isset($data_resource->buyer->email) ) {
																$wm_buyer_email_aux = $data_resource->buyer->email;
															}
															$order->set_billing_email( apply_filters( 'woomelly_email_wc_order', filter_var($wm_buyer_email_aux, FILTER_SANITIZE_EMAIL), $code ) );
															//cart
																if ( $is_cart_order == true ) {
																	//$wm_order->set_woomelly_cart_order_id(sprintf('%.0f', $data_resource->pack_id));
																	$wm_order->set_woomelly_cart_order_id( $data_resource->pack_id );
																	if ( !in_array($data_resource->id, $wm_order->get_woomelly_code_order_cart()) ) {
																		foreach ( $data_resource->order_items as $value ) {
																			$wmitemid = $value->item->id;
																			$wmvariationid = $value->item->variation_id;
																			$wm_product = null;
																			if ( isset($value->item->variation_id) && $value->item->variation_id!="" ) {
																				$wm_product = wm_get_product_by_code( $value->item->variation_id, false );
																				if ( $wm_product == null ) {
																					$wm_product = wm_get_product_by_code( $value->item->id );
																				}
																			} else {
																				$wm_product = wm_get_product_by_code( $value->item->id );
																			}
																			if ( $wm_product != null ) {
																				$quantity = intval($value->quantity);
																				$quantity_reduce = $quantity;
																				$meli_order_operation = 'decrease';
																				if ( apply_filters( 'woomelly_enable_decrease_stock_extsales_inactive', false ) == true ) {
																					unset( $data_item_stock );
																					$data_item_stock = WMeli::get_item( $value->item->id, false, null, null, $wm_settings_page );
																					if ( is_object($data_item_stock) ) {
																						if ( isset($value->item->variation_id) && $value->item->variation_id!="" && !empty($data_item_stock->variations) ) {
																							$wm_aux_break = false;
																							foreach ( $data_item_stock->variations as $meli_variation ) {
																								if ( $wm_aux_break == false ) {
																									if ( $meli_variation->id == $value->item->variation_id ) {
																										$quantity_reduce = $meli_variation->available_quantity;
																										$meli_order_operation = 'set';
																										$wm_aux_break = true;
																									}
																								}
																							}
																						} else {
																							$quantity_reduce = $data_item_stock->available_quantity;
																							$meli_order_operation = 'set';
																						}
																					}
																				}
																				$line_item = new WC_Order_Item_Product();
																				$product_line_item = wc_get_product( $wm_product->get_id() );
																				if ( is_object($product_line_item) ) {
																					if ( wm_exist_item_line( $order, $product_line_item, $line_item, $data_resource, $wm_settings_page ) == false ) {
																						$wm_order->set_woomelly_code_order_cart($data_resource->id);
																						$line_item->set_product( $product_line_item );
																						$line_item->set_quantity( $quantity );
																						if ( $wm_woo_product == true ) {
																							//bundle
																								$woosb_ids = wm_get_meta_data( $wm_product->get_id(), 'woosb_ids', true );
																								//$woosb_ids = get_post_meta( $wm_product->get_id(), 'woosb_ids', true );
																								if ( $woosb_ids && $woosb_ids != "" && !is_array($woosb_ids) ) {
																									$woosb_items = explode( ',', $woosb_ids );
																									if ( is_array( $woosb_items ) && count( $woosb_items ) > 0 ) {
																										unset($woosb_items);
																										if ( wm_get_meta_data( $wm_product->get_id(), 'woosb_disable_auto_price', true ) === 'on' ) {
																										//if ( get_post_meta( $wm_product->get_id(), 'woosb_disable_auto_price', true ) === 'on' ) {
																											$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																										} else {
																											$price_exc_tax = 0;
																										}
																									} else {
																										$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																									}
																								} else {
																									$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																								}
																							//bundle
																						} else {
																							$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																						}
																						$line_item->set_total( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																						$line_item->set_subtotal( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																						//$line_item->set_subtotal( $price_exc_tax );
																						$line_item->add_meta_data( 'itemid', $wmitemid, false );
																						$line_item->add_meta_data( 'variationid', $wmvariationid, false );
																						$order->add_item( $line_item );
																						if ( $wm_settings_page->get_extension_order_reduce_inventory() == 'active' && $it_will_reduce_stock == true && $woocommerce_status != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') && $woocommerce_status != apply_filters('wm_filter_wc_status_failed', 'failed') ) {
																							wm_reduce_productwoo_stock( $product_line_item, $quantity_reduce, $order, $meli_order_operation );
																						}
																						//bundle
																						if ( $wm_woo_product == true ) {
																							$wm_woo_list_products[] = $wm_product;
																							$woosb_arr = array();
																							$woosb_ids = wm_get_meta_data( $wm_product->get_id(), 'woosb_ids', true );
																							//$woosb_ids = get_post_meta( $wm_product->get_id(), 'woosb_ids', true );
																							if ( $woosb_ids && $woosb_ids != "" && !is_array($woosb_ids) ) {
																								$woosb_items = explode( ',', $woosb_ids );
																								if ( is_array( $woosb_items ) && count( $woosb_items ) > 0 ) {
																									foreach ( $woosb_items as $woosb_item ) {
																										if ( !is_array($woosb_item) ) {
																											$woosb_item_arr = explode( '/', $woosb_item );
																											$woosb_arr[]    = array(
																												'id'  => intval( isset( $woosb_item_arr[0] ) ? $woosb_item_arr[0] : 0 ),
																												'qty' => intval( isset( $woosb_item_arr[1] ) ? $woosb_item_arr[1] : 1 )
																											);
																										}
																									}
																								}
																							}
																							if ( !empty($woosb_arr) ) {
																								$is_price_zero = false;
																								if ( $price_exc_tax > 0 ) {
																									$is_price_zero = true;
																								}
																								foreach ( $woosb_arr as $value_woosb ) {
																									if ( intval($value_woosb['id']) > 0 ) {
																										$line_item_woosb = new WC_Order_Item_Product();
																										$product_line_item_woosb = wc_get_product( $value_woosb['id'] );
																										if ( is_object($product_line_item_woosb) ) {
																											$wm_woo_list_products[] = $value_woosb['id'];
																											$line_item_woosb->set_product( $product_line_item_woosb );
																											$line_item_woosb->set_quantity( ($value_woosb['qty'] * $quantity) );
																											$price_exc_tax = 0;
																											if ( $is_price_zero == false ) {
																												$price_exc_tax = wc_get_price_excluding_tax($product_line_item_woosb, array( 'qty' => ($value_woosb['qty'] * $quantity), 'price' => $product_line_item_woosb->get_price() ) );
																											}
																											$line_item_woosb->set_total( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																											$line_item_woosb->set_subtotal( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																											//$line_item_woosb->set_subtotal( $price_exc_tax );
																											$order->add_item( $line_item_woosb );
																											if ( $wm_settings_page->get_extension_order_reduce_inventory() == 'active' && $it_will_reduce_stock == true && $woocommerce_status != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') && $woocommerce_status != apply_filters('wm_filter_wc_status_failed', 'failed') ) {
																												wm_reduce_productwoo_stock( $product_line_item_woosb, ($value_woosb['qty'] * $quantity_reduce), $order, $meli_order_operation );
																											}
																										}
																										unset( $line_item_woosb );
																										unset( $product_line_item_woosb );
																									}
																								}
																							}
																						} else if ( $product_line_item->get_type() == 'bundle' && $is_wc_bundle == true ) {
																							$wm_woo_list_products[] = $wm_product;
																							$bundled_items = $product_line_item->get_bundled_items();
																							if ( !empty($bundled_items) ) {
																								foreach ( $bundled_items as $bundled_item ) {
																									$line_item_woosb = new WC_Order_Item_Product();
																									$product_line_item_woosb = $bundled_item->product;
																									$wm_woo_list_products[] = $product_line_item_woosb;
																									$line_item_woosb->set_product( $product_line_item_woosb );
																									$line_item_woosb->set_quantity( ($bundled_item->get_quantity()*$quantity) );
																									$price_exc_tax = wc_get_price_excluding_tax($product_line_item_woosb, array( 'qty' => ($bundled_item->get_quantity()*$quantity), 'price' => $bundled_item->get_raw_regular_price() ) );
																									$line_item_woosb->set_total( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																									$line_item_woosb->set_subtotal( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																									//$line_item_woosb->set_subtotal( $price_exc_tax );
																									$order->add_item( $line_item_woosb );
																									if ( $wm_settings_page->get_extension_order_reduce_inventory() == 'active' && $it_will_reduce_stock == true && $woocommerce_status != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') && $woocommerce_status != apply_filters('wm_filter_wc_status_failed', 'failed') ) {
																										wm_reduce_productwoo_stock( $product_line_item_woosb, ($bundled_item->get_quantity()*$quantity_reduce), $order, $meli_order_operation );
																									}
																									unset( $line_item_woosb );
																									unset( $product_line_item_woosb );
																								}
																							}
																						}
																						//bundle
																						if ( $product_line_item->is_type( 'variation' ) ) {
																							$wc_parent_id = $product_line_item->get_parent_id();
																							$product_line_item_lyid = wc_get_product( $wc_parent_id );
																						} else {
																							$product_line_item_lyid = $product_line_item;
																						}
																						if ( is_object($product_line_item_lyid) ) {
																							$wm_product_line_item = new WMProduct( $product_line_item_lyid->get_id() );
																							if ( $wm_product_line_item->get_id() > 0 ) {
																								if ( $wm_settings_page->get_extension_order_ml_fee() == 'active' ) {
																									$sale_fee_amount = floatval($value->sale_fee);
																									$sale_fee_amount = $sale_fee_amount * intval($value->quantity);
																									$sale_fee_amount = apply_filters( 'woomelly_set_meli_fee_order', ($sale_fee_amount) * (-1), $data_resource, $product_line_item_lyid, $order, $wm_settings_page );
																									$fee = new WC_Order_Item_Fee();
																									$fee->set_amount( $sale_fee_amount );
																									$fee->set_total( $sale_fee_amount );
																									$fee->set_name( sprintf(__('ML sale fee (%s) by %s', 'woomelly'), wm_get_name_listing_type($value->listing_type_id), $product_line_item_lyid->get_name()) );
																									$order->add_item( $fee );
																									unset($fee);
																								}
																							}
																							unset($wm_product_line_item);
																						}
																						unset($product_line_item_lyid);
																					} else {
																						$wm_order->set_woomelly_code_order_cart($data_resource->id);
																					}
																				}
																				if ( $data_resource->status != 'cancelled' ) {
																					$wm_product->set_woomelly_order($data_resource->id);
																				} else {
																					$wm_product->set_woomelly_order_cancelled($data_resource->id);
																				}

																				unset( $product_line_item );
																				unset( $line_item );
																			}
																			unset( $wm_product );
																		}
																		$order->calculate_totals( $wm_settings_page->get_extension_order_woo_fee(true) );
																		$order->save();
																		//bundle
																		if ( $wm_woo_product == true ) {
																			$wm_list_irder_items = $order->get_items();
																			if ( !empty($wm_list_irder_items) && !empty($wm_woo_list_products) ) {
																				$wm_woo_product_temp = $wm_woo_list_products[0];
																				unset( $wm_woo_list_products[0] );
																				foreach ( $wm_list_irder_items as $item_id => $item ) {
																					$product_id_temp = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
																					if ( in_array($product_id_temp, $wm_woo_list_products) ) {
																						wc_add_order_item_meta( $item_id, '_woosb_parent_id', $wm_woo_product_temp->get_id() );
																					}
																				}
																			}
																			unset( $wm_list_irder_items );
																		}
																		//bundle
																	}
																}
															//cart
															if ( is_object($data_resource->status_detail) && isset($data_resource->status_detail->description) ) {
																$notes = $data_resource->status_detail->description;
															}
															$status_now = '';										
															if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																$status_now = $order->get_status();
															} else {
																$status_now = $wm_order->get_woomelly_status_field();
															}
															if ( $status_now != apply_filters('wm_filter_wc_status_failed', 'failed') && $status_now != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
																//if ( is_object($data_resource->feedback) && isset($data_resource->feedback->purchase) && $data_resource->feedback->purchase!="" && $woocommerce_status != 'failed' ) {
																$data_resource_tags = array();
																if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
																	$data_resource_tags = $data_resource->tags;
																}
																$is_delivered = in_array( "delivered", $data_resource_tags );
																unset( $data_resource_tags );
																if ( $data_review == null ) $data_review = WMeli::get_orders( $code, 'feedback', $wm_settings_page );
																if ( (is_object($data_review) && isset($data_review->sale) && is_object($data_review->sale) && $data_review->sale!=null) || ($is_delivered) ) {
																	$wm_order->set_meli_feedback_info($data_review);
																	if ( (isset($data_review->sale->fulfilled) && $data_review->sale->fulfilled==true) || $is_delivered ) {
																		if ( $status_now != apply_filters('wm_filter_wc_status_completed', 'completed') ) {
																			if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																				$order->update_status( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			} else {
																				$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			}
																			if ( wm_has_mediations($data_resource->mediations) == false && !in_array('completed', $wm_order->get_woomelly_messages()) ) {
																				$woomelly_get_message = new WMMessage();
																				$woomelly_get_message->send_message( false, 'completed', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page, true );
																				$wm_order->set_woomelly_messages( 'completed' );
																			}
																		}
																	} else if ( ($data_resource->status == 'confirmed' || $data_resource->status == 'paid' || $data_resource->status == 'cancelled' ) && $status_now != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
																		//$order->update_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																			$order->set_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																			$order->set_total(0);
																			$order->save();
																		} else {
																			$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		}
																		if ( wm_has_mediations($data_resource->mediations) == false && !in_array('cancelled', $wm_order->get_woomelly_messages()) ) {
																			$woomelly_get_message = new WMMessage();
																			$woomelly_get_message->send_message( false, 'cancelled', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page, true );
																			$wm_order->set_woomelly_messages( 'cancelled' );
																		}
																	}
																} else {
																	if ( $status_now != apply_filters('wm_filter_wc_status_completed', 'completed') || ($status_now==apply_filters('wm_filter_wc_status_completed', 'completed') && $woocommerce_status==apply_filters('wm_filter_wc_status_failed', 'failed')) ) {
																		if ( $status_now != $woocommerce_status ) {
																			if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																				$order->update_status( $woocommerce_status, $notes, true );
																			} else {
																				$wm_order->set_woomelly_status_field( $woocommerce_status );
																			}
																			if ( wm_has_mediations($data_resource->mediations) == false && !in_array(apply_filters('wm_filter_wc_status_woocommerce', $woocommerce_status), $wm_order->get_woomelly_messages()) ) {
																				$woomelly_get_message = new WMMessage();
																				$woomelly_get_message->send_message( false, apply_filters('wm_filter_wc_status_woocommerce', $woocommerce_status), $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page, true );
																				$wm_order->set_woomelly_messages( apply_filters('wm_filter_wc_status_woocommerce', $woocommerce_status) );
																			}
																		}											
																	}											
																}
															} else {
																$data_resource_tags = array();
																if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
																	$data_resource_tags = $data_resource->tags;
																}															
																$is_delivered = in_array( "delivered", $data_resource_tags );
																unset( $data_resource_tags );
																if ( $data_review == null ) $data_review = WMeli::get_orders( $code, 'feedback', $wm_settings_page );
																if ( (is_object($data_review) && isset($data_review->sale) && is_object($data_review->sale) && $data_review->sale!=null) || $is_delivered ) {
																	$wm_order->set_meli_feedback_info($data_review);
																	if ( (isset($data_review->sale->fulfilled) && $data_review->sale->fulfilled==true) || $is_delivered ) {
																		if ( $status_now != apply_filters('wm_filter_wc_status_completed', 'completed') ) {
																			if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																				$order->update_status( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			} else {
																				$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			}
																			if ( wm_has_mediations($data_resource->mediations) == false && !in_array('completed', $wm_order->get_woomelly_messages()) ) {
																				$woomelly_get_message = new WMMessage();
																				$woomelly_get_message->send_message( false, 'completed', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page, true );
																				$wm_order->set_woomelly_messages( 'completed' );
																			}
																		}
																	} else if ( ($data_resource->status == 'confirmed' || $data_resource->status == 'paid' || $data_resource->status == 'cancelled' ) && $status_now != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
																		//$order->update_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																			$order->set_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																			$order->set_total(0);
																			$order->save();
																		} else {
																			$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		}
																		if ( wm_has_mediations($data_resource->mediations) == false && !in_array('cancelled', $wm_order->get_woomelly_messages()) ) {
																			$woomelly_get_message = new WMMessage();
																			$woomelly_get_message->send_message( false, 'cancelled', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page, true );
																			$wm_order->set_woomelly_messages( 'cancelled' );
																		}
																	}
																}
															}
															$tags['{shipping_address}'] = $order->get_shipping_address_1() . " " . $order->get_shipping_city() . ", " . $order->get_shipping_state() . " " . $order->get_shipping_country();
														}
														if ( !empty($data_resource->payments) && is_object($order) && $order->get_status() != "trash" && $order->get_payment_method() == "" ) {
															wm_set_order_payment( $order, $wm_payment_id, $data_resource, $wm_settings_page, true );
														}
														$wm_order->set_woomelly_last_updated( $data_resource->last_updated );
														if ( is_object($data_shipping) ) {
															$wm_order->set_woomelly_shipping_last_updated( $data_shipping->last_updated );
														}
														$data_resource_tags = array();
														if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
															$data_resource_tags = $data_resource->tags;
														}													
														$wm_order->set_woomelly_tags( $data_resource_tags );
														if ( isset($data_resource->context) ) {
															if ( isset($data_resource->context->channel) ) {
																$wm_order->set_woomelly_channel( $data_resource->context->channel );
															}
															if ( isset($data_resource->context->flows) ) {
																$wm_order->set_woomelly_flows( $data_resource->context->flows );
															}
														}
														unset ( $data_resource_tags );
													}
												} else if ( $data_resource->status == 'cancelled' && $wm_order->get_woomelly_status_field() != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
													if ( $wm_order->get_woomelly_sync_status_field() && $wm_settings_page->get_extension_order_status() == 'active' ) {
														$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
														$order = wc_get_order( $wm_order->get_id() );
														if ( is_object($order) && $order->get_status() != "trash" ) {
															$wm_order->set_woomelly_manufacturing_ending_date( $manufacturing_ending_date );
															$order->update_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
															if ( wm_has_mediations($data_resource->mediations) == false && !in_array('cancelled', $wm_order->get_woomelly_messages()) ) {
																$woomelly_get_message = new WMMessage();
																$woomelly_get_message->send_message( false, 'cancelled', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page, true );
																$wm_order->set_woomelly_messages( 'cancelled' );
															}
														}
													}
												}
											} else {
												if ( !isset($data_resource->buyer) || !isset($data_resource->buyer->first_name) ) {
													unset( $data_resource );
													$data_resource = WMeli::get_resource( $resource, $wm_settings_page );
												}
												if ( is_object($data_resource) ) {
													unset( $wm_order );
													global $wpdb;
													$wpdb->query('START TRANSACTION');
													try {
														$order = new WC_Order( 0 );
														$order->set_created_via( 'woomelly_mercadolibre' );
														$order->set_customer_note( __('Order from MercadoLibre', 'woomelly') );
														$order->set_currency( $woocommerce_currency_id );
														wm_set_order_payment( $order, $wm_payment_id, $data_resource, $wm_settings_page );
														$wm_orde_phone = wm_set_order_phone( $data_resource, $wm_settings_page );
														$meli_billing_info_request = WMeli::get_orders( $code, 'billing_info', $wm_settings_page );
														if ( is_object($meli_billing_info_request) && isset($meli_billing_info_request->billing_info) ) {
															if ( isset($meli_billing_info_request->billing_info->doc_number) && !is_null($meli_billing_info_request->billing_info->doc_number) ) {
																$meli_billing_info = trim($meli_billing_info_request->billing_info->doc_number);
															}
															if ( isset($meli_billing_info_request->billing_info->doc_type) && !is_null($meli_billing_info_request->billing_info->doc_type) ) {
																$meli_doc_type = trim($meli_billing_info_request->billing_info->doc_type);
															}
														} else if ( is_object($meli_billing_info_request) && isset($meli_billing_info_request->buyer) ) {
															if ( isset($meli_billing_info_request->buyer->billing_info->identification) && isset($meli_billing_info_request->buyer->billing_info->identification->number) && !is_null($meli_billing_info_request->buyer->billing_info->identification->number) ) {
																$meli_billing_info = trim($meli_billing_info_request->buyer->billing_info->identification->number);
															}
															if ( isset($meli_billing_info_request->buyer->billing_info->identification) && isset($meli_billing_info_request->buyer->billing_info->identification->type) && !is_null($meli_billing_info_request->buyer->billing_info->identification->type) ) {
																$meli_doc_type = trim($meli_billing_info_request->buyer->billing_info->identification->type);
															}
														}
														$wm_buyer_email_aux = "";
														if ( isset($data_resource->buyer->email) ) {
															$wm_buyer_email_aux = $data_resource->buyer->email;
														}
														$meli_buyer = array(
															'first_name' => ucwords( mb_strtolower( $data_resource->buyer->first_name ) ),
															'last_name'  => ucwords( mb_strtolower( $data_resource->buyer->last_name ) ),
															'company'    => $meli_billing_info,
															'email'      => apply_filters( 'woomelly_email_wc_order', filter_var($wm_buyer_email_aux, FILTER_SANITIZE_EMAIL), $code ),
															'phone'      => $wm_orde_phone,
															'address_1'  => apply_filters( 'woomelly_string_address_wc_order', __("Address by default", "woomelly") ),
															'address_2'  => '', 
															'city'       => '',
															'state'      => '',
															'postcode'   => '',
															'country'    => wm_list_country_codes( $wm_settings_page->get_site_id() )
														);
														if ( is_object($data_resource->shipping) && isset($data_resource->shipping->id) && $data_resource->shipping->id != null && $data_resource->shipping->id != "" ) {
															// Get the datails from shipping (not users)
														} else {
															wm_get_extension_order_address_buyer ( $data_resource, $meli_buyer, $wm_settings_page );
															$order->set_address( $meli_buyer, 'billing' );
														}
														$total_amount = floatval($data_resource->total_amount);
														foreach ( $data_resource->order_items as $value ) {
															$wmitemid = $value->item->id;
															$wmvariationid = $value->item->variation_id;
															$wm_product = null;
															if ( isset($value->item->variation_id) && $value->item->variation_id!="" ) {
																$wm_product = wm_get_product_by_code( $value->item->variation_id, false );
																if ( $wm_product == null ) {
																	$wm_product = wm_get_product_by_code( $value->item->id );
																}
															} else {
																$wm_product = wm_get_product_by_code( $value->item->id );
															}
															if ( $wm_product != null ) {
																$tags['{product_title}'] = $value->item->title;
																$quantity = intval($value->quantity);
																$tags['{product_quantity}'] = $quantity;
																$line_item = new WC_Order_Item_Product();
																$product_line_item = wc_get_product( $wm_product->get_id() );
																if ( is_object($product_line_item) ) {
																	if ( wm_exist_item_line ( $order, $product_line_item, $line_item, $data_resource, $wm_settings_page ) == false ) {
																		$line_item->set_product( $product_line_item );
																		$line_item->set_quantity( $quantity );
																		if ( $wm_woo_product == true ) {
																			//bundle
																			$woosb_ids = wm_get_meta_data( $wm_product->get_id(), 'woosb_ids', true );
																			//$woosb_ids = get_post_meta( $wm_product->get_id(), 'woosb_ids', true );
																			if ( $woosb_ids && $woosb_ids != "" && !is_array($woosb_ids) ) {
																				$woosb_items = explode( ',', $woosb_ids );
																				if ( is_array( $woosb_items ) && count( $woosb_items ) > 0 ) {
																					unset( $woosb_items );
																					if ( wm_get_meta_data( $wm_product->get_id(), 'woosb_disable_auto_price', true ) === 'on' ) {
																					//if ( get_post_meta( $wm_product->get_id(), 'woosb_disable_auto_price', true ) === 'on' ) {
																						$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																					} else {
																						$price_exc_tax = 0;
																					}
																				} else {
																					$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																				}
																			} else {
																				$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																			}
																			//bundle
																		} else {
																			$price_exc_tax = wc_get_price_excluding_tax($product_line_item, array( 'qty' => $quantity, 'price' => $value->unit_price ) );
																		}
																		$line_item->set_total( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																		$line_item->set_subtotal( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																		//@new
																		//$line_item->set_subtotal( $price_exc_tax );
																		//@old
																		//$line_item->set_subtotal( floatval($value->unit_price) * $quantity );
																		$line_item->add_meta_data( 'itemid', $wmitemid, false );
																		$line_item->add_meta_data( 'variationid', $wmvariationid, false );
																		$order->add_item( $line_item );
																		//bundle
																		if ( $wm_woo_product == true ) {
																			$wm_woo_list_products[] = $wm_product;
																			$woosb_arr = array();
																			$woosb_ids = wm_get_meta_data( $wm_product->get_id(), 'woosb_ids', true );
																			//$woosb_ids = get_post_meta( $wm_product->get_id(), 'woosb_ids', true );
																			if ( $woosb_ids && $woosb_ids != "" && !is_array($woosb_ids) ) {
																				$woosb_items = explode( ',', $woosb_ids );
																				if ( is_array( $woosb_items ) && count( $woosb_items ) > 0 ) {
																					foreach ( $woosb_items as $woosb_item ) {
																						if ( !is_array($woosb_item) ) {
																							$woosb_item_arr = explode( '/', $woosb_item );
																							$woosb_arr[]    = array(
																								'id'  => intval( isset( $woosb_item_arr[0] ) ? $woosb_item_arr[0] : 0 ),
																								'qty' => intval( isset( $woosb_item_arr[1] ) ? $woosb_item_arr[1] : 1 )
																							);
																						}
																					}
																				}
																			}
																			if ( !empty($woosb_arr) ) {
																				$is_price_zero = false;
																				if ( $price_exc_tax > 0 ) {
																					$is_price_zero = true;
																				}
																				foreach ( $woosb_arr as $value_woosb ) {
																					if ( intval($value_woosb['id']) > 0 ) {
																						$line_item_woosb = new WC_Order_Item_Product();
																						$product_line_item_woosb = wc_get_product( $value_woosb['id'] );
																						if ( is_object($product_line_item_woosb) ) {
																							$wm_woo_list_products[] = $product_line_item_woosb;
																							$line_item_woosb->set_product( $product_line_item_woosb );
																							$line_item_woosb->set_quantity( ($value_woosb['qty']*$quantity) );
																							$price_exc_tax = 0;
																							if ( $is_price_zero == false ) {
																								$price_exc_tax = wc_get_price_excluding_tax($product_line_item_woosb, array( 'qty' => ($value_woosb['qty']*$quantity), 'price' => $product_line_item_woosb->get_price() ) );
																							}
																							$line_item_woosb->set_total( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																							$line_item_woosb->set_subtotal( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																							//$line_item_woosb->set_subtotal( $price_exc_tax );
																							$order->add_item( $line_item_woosb );
																						}
																						unset( $line_item_woosb );
																						unset( $product_line_item_woosb );
																					}
																				}
																			}
																		} else if ( $product_line_item->get_type() == "bundle" ) {
																			$wm_woo_list_products[] = $wm_product;
																			$bundled_items = $product_line_item->get_bundled_items();
																			if ( !empty($bundled_items) ) {
																				foreach ( $bundled_items as $bundled_item ) {
																					$line_item_woosb = new WC_Order_Item_Product();
																					$product_line_item_woosb = $bundled_item->product;
																					$wm_woo_list_products[] = $product_line_item_woosb;
																					$line_item_woosb->set_product( $product_line_item_woosb );
																					$line_item_woosb->set_quantity( ($bundled_item->get_quantity()*$quantity) );
																					$price_exc_tax = wc_get_price_excluding_tax($product_line_item_woosb, array( 'qty' => ($bundled_item->get_quantity()*$quantity), 'price' => $bundled_item->get_raw_regular_price() ) );
																					$line_item_woosb->set_total( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																					$line_item_woosb->set_subtotal( apply_filters( 'woomelly_set_price_order_item', $price_exc_tax, $product_line_item, $value, $data_resource, $wm_settings_page ) );
																					//$line_item_woosb->set_subtotal( $price_exc_tax );
																					$order->add_item( $line_item_woosb );
																					unset( $line_item_woosb );
																					unset( $product_line_item_woosb );
																				}
																			}
																		}
																		//bundle							
																		if ( $product_line_item->is_type( 'variation' ) ) {
																			$wc_parent_id = $product_line_item->get_parent_id();
																			$product_line_item_lyid = wc_get_product( $wc_parent_id );
																		} else {
																			$product_line_item_lyid = $product_line_item;
																		}
																		if ( is_object($product_line_item_lyid) ) {
																			$wm_product_line_item = new WMProduct( $product_line_item_lyid->get_id() );
																			if ( $wm_product_line_item->get_id() > 0 ) {
																				if ( $wm_settings_page->get_extension_order_ml_fee() == 'active' ) {
																					$sale_fee_amount = floatval($value->sale_fee);
																					$sale_fee_amount = $sale_fee_amount * intval($value->quantity);
																					$sale_fee_amount = apply_filters( 'woomelly_set_meli_fee_order', ($sale_fee_amount) * (-1), $data_resource, $product_line_item_lyid, $order, $wm_settings_page );
																					$fee = new WC_Order_Item_Fee();
																					$fee->set_amount( $sale_fee_amount );
																					$fee->set_total( $sale_fee_amount );
																					$fee->set_name( sprintf(__('ML sale fee (%s) by %s', 'woomelly'), wm_get_name_listing_type($value->listing_type_id), $product_line_item_lyid->get_name()) );
																					$order->add_item( $fee );
																					unset($fee);
																				}
																			}
																			unset($wm_product_line_item);
																		}
																		unset($product_line_item_lyid);
																	}
																}
																if ( $data_resource->status != 'cancelled' ) {
																	$wm_product->set_woomelly_order($data_resource->id);
																} else {
																	$wm_product->set_woomelly_order_cancelled($data_resource->id);
																}
																		
																unset( $product_line_item );
																unset( $line_item );
															}
															if ( isset($value->item->category_id) && $value->item->category_id != "" ) {
																$all_data_category = WMeli::get_category( $value->item->category_id, null, $wm_settings_page );
																if ( !empty($all_data_category) ) {
																	if ( isset($all_data_category->settings) && isset($all_data_category->settings->vertical) ) {
																		$meli_category_id = $all_data_category->settings->vertical;
																	}
																}
															}
															unset( $wm_product );
														}
														if ( is_object($data_resource->shipping) && isset($data_resource->shipping->id) && $data_resource->shipping->id != null && $data_resource->shipping->id != "" ) {
															if ( $data_shipping == null ) {
																$data_shipping = WMeli::get_shipping( $data_resource->shipping->id, $wm_settings_page );
															}
															if ( is_object($data_shipping) ) {
																if ( isset($data_shipping->mode, $data_shipping->status) && $data_shipping->mode == 'custom' && $data_shipping->status == "cancelled" ) {
																	$woocommerce_status = "cancelled";
																}
																$tags['{tracking_number}']  = $data_shipping->tracking_number;
																/*$data_shipping_tracking = WMeli::get_shipping( $data_resource->shipping->id . '/carrier', $wm_settings_page );
																if ( is_object($data_shipping_tracking) && isset($data_shipping_tracking->url) && $data_shipping_tracking->url != "" ) {
																	$the_url = $data_shipping_tracking->url;
																	$the_url = str_replace('#{orderId}', $code, $the_url);
																	$the_url = str_replace('#{shipmentId}', $data_resource->shipping->id, $the_url);
																	$tags['{tracking_number_url}'] = '<a href="'.$the_url.'">'.__("click here", "woomelly").'</a>';
																}*/
																$wm_shipping_status = $data_shipping->status;
																if ( isset($data_shipping->shipping_mode) && !is_null($data_shipping->shipping_mode) && $data_shipping->shipping_mode!="" ) {
																	$shipping_mode = $data_shipping->shipping_mode;
																} else if ( isset($data_shipping->mode) && !is_null($data_shipping->mode) && $data_shipping->mode!="" ) {
																	$shipping_mode = $data_shipping->mode;
																}
																if ( isset($data_shipping->shipping_option->name) && !is_null($data_shipping->shipping_option->name) && $data_shipping->shipping_option->name!="" && $data_shipping->shipping_option->name!="add_shipping_cost" ) {
																	$shipping_option_name = ' | ' . $data_shipping->shipping_option->name;
																}
																if ( isset($data_shipping->receiver_address->address_line) && !is_null($data_shipping->receiver_address->address_line) && $data_shipping->receiver_address->address_line != "" ) {
																	$address_1 = trim($data_shipping->receiver_address->address_line);    
																}
																if ( isset($data_shipping->receiver_address->city, $data_shipping->receiver_address->city->name) && !is_null($data_shipping->receiver_address->city->name) && $data_shipping->receiver_address->city->name != "" ) {
																	$city = trim($data_shipping->receiver_address->city->name);
																}
																if ( isset($data_shipping->receiver_address->street_name) && !is_null($data_shipping->receiver_address->street_name) && $data_shipping->receiver_address->street_name != "" ) {
																	$street_name = trim($data_shipping->receiver_address->street_name);
																}
																if ( isset($data_shipping->receiver_address->street_number) && !is_null($data_shipping->receiver_address->street_number) && $data_shipping->receiver_address->street_number != "" ) {
																	$street_number = trim($data_shipping->receiver_address->street_number);
																}
																if ( isset($data_shipping->receiver_address->zip_code) && !is_null($data_shipping->receiver_address->zip_code) && $data_shipping->receiver_address->zip_code != "" ) {
																	$postcode = trim($data_shipping->receiver_address->zip_code);
																}
																if ( isset($data_shipping->receiver_address->neighborhood, $data_shipping->receiver_address->neighborhood->name) && !is_null($data_shipping->receiver_address->neighborhood->name) && $data_shipping->receiver_address->neighborhood->name != "" ) {
																	$neighborhood = trim($data_shipping->receiver_address->neighborhood->name);
																}
																if ( isset($data_shipping->receiver_address->comment) && !is_null($data_shipping->receiver_address->comment) && $data_shipping->receiver_address->comment != "" ) {
																	$comment_ref = trim($data_shipping->receiver_address->comment);
																	$order->set_customer_note( $comment_ref );
																}
																if ( isset($data_shipping->receiver_address->receiver_name) && !is_null($data_shipping->receiver_address->receiver_name) && $data_shipping->receiver_address->receiver_name != "" ) {
																	$receiver_name = ucwords( mb_strtolower( trim($data_shipping->receiver_address->receiver_name) ) );
																} else {
																	$receiver_name = ucwords( mb_strtolower( trim($data_resource->buyer->first_name) ) );
																}
																if ( isset($data_shipping->receiver_address->state, $data_shipping->receiver_address->state->id) )
																	$state = wm_get_extension_order_address_buyer( null, $meli_buyer, $wm_settings_page, $data_shipping->receiver_address->state->id );
																$wm_orde_phone = wm_set_order_phone( $data_resource, $wm_settings_page );
																$meli_shipping = array(
																	'first_name' => $receiver_name,
																	'last_name'  => '',
																	'company'    => $meli_billing_info,
																	'phone'      => $wm_orde_phone,
																	'address_1'  => $address_1,
																	'address_2'  => '',
																	'city'       => $city,
																	'state'      => $state,
																	'postcode'   => $postcode,
																	'country'    => wm_list_country_codes( $wm_settings_page->get_site_id() )
																);
																$tags['{shipping_address}'] = $meli_shipping['address_1'] . " " . $meli_shipping['city'] . ", " . $meli_shipping['state'] . " " . $meli_shipping['country'];
																$order->set_address( $meli_shipping, 'shipping' );
																$meli_buyer['state'] = $state;
																$meli_buyer['city'] = $city;
																$meli_buyer['address_1'] = $address_1;
																$meli_buyer['postcode'] = $postcode;
																$order->set_address( $meli_buyer, 'billing' );
																if ( $shipping_mode == 'not_specified' ) {
																	$shipping_option_name = __('Without Shipping', 'woomelly');
																} else if ( $shipping_mode == 'custom' ) {
																	$shipping_option_name = sprintf( __('Custom %s', 'woomelly'), $shipping_option_name );
																} else if ( $shipping_mode == 'me1' ) {
																	$shipping_option_name = sprintf( __('Mercado Envios type 1 %s', 'woomelly'), $shipping_option_name );
																} else if ( $shipping_mode == 'me2' ) {
																	$shipping_option_name = sprintf( __('Mercado Envios %s', 'woomelly'), $shipping_option_name );
																}
																$ext_order_ml_shipping = $wm_settings_page->get_extension_order_ml_shipping();
																if ( $ext_order_ml_shipping != 'inactive' ) {
																	$item_shipping = new WC_Order_Item_Shipping();
																	if ( $ext_order_ml_shipping == 'active_seller' ) {
																		$total_shipping = floatval( $data_shipping->shipping_option->cost );
																		$total_list_cost = floatval( $data_shipping->shipping_option->list_cost );
																		if ( $shipping_mode == 'me2' && $total_shipping == 0 && $total_list_cost > 0 && $data_shipping->logistic_type != "self_service" ) {
																			$total_shipping = $total_list_cost * (-1);
																		} else if ( $shipping_mode == 'me2' && $total_shipping > 0 && $total_list_cost > 0 && $data_shipping->logistic_type != "self_service" ) {
																			//$total_shipping = $total_list_cost * (-1);
																			//WMlog::set_log( __("fix made in v2.5.1 to avoid duplicating shipments within the order...", "woomelly") . serialize($data_shipping), 'error' );
																			$item_shipping_free = new WC_Order_Item_Shipping();
																			$item_shipping_free->set_props( array(
																				'method_title' => $shipping_option_name,
																				'method_id'    => 0,
																				'total'        => ( $total_list_cost * (-1) ),
																				'taxes'        => 0,
																			) );
																			$item_shipping_free->add_meta_data( 'shipmentid', $data_shipping->id, false );
																			$item_shipping_free->save();
																			$order->add_item( $item_shipping_free );
																		} else if ( $shipping_mode == 'me2' && $data_shipping->logistic_type == "self_service" ) {
																			/*if ( floatval($data_shipping->cost_components->ratio) > 0 && floatval($data_shipping->order_cost) < 1999 ) {
																				$total_shipping = 0;
																			} else if ( floatval($data_shipping->cost_components->ratio) > 0 && floatval($data_shipping->order_cost) >= 1999 ) {
																				$total_shipping = floatval($data_shipping->order_cost);
																			} else if ( floatval($data_shipping->cost_components->ratio) == 0 && floatval($data_shipping->cost_components->loyal_discount) > 0 && $total_shipping > 0 ) {
																				$por_discount_total = 1 - floatval($data_shipping->cost_components->loyal_discount);
																				$por_discount = floatval($data_shipping->cost_components->loyal_discount) * 100;
																				$total_shipping = $total_shipping + (round(($total_shipping * $por_discount) / 80));
																			}*/
																			if ( floatval($data_shipping->cost_components->ratio) > 0 ) {
																				/*$total_shipping = floatval($data_shipping->cost_components->ratio);
																				$total_shipping = $total_shipping * (-1);*/
																				$total_shipping = floatval( $data_shipping->shipping_option->cost );
																				if ( $total_shipping == 0 ) {
					        														$data_shipping_gross_amount = WMeli::get_shipping( $data_shipping->id . '/costs', $wm_settings_page );
					        														if ( !empty($data_shipping_gross_amount) && isset($data_shipping_gross_amount->senders) && is_array($data_shipping_gross_amount->senders) ) {
					        														    if ( !empty($data_shipping_gross_amount->senders) ) {
					        														        foreach ( $data_shipping_gross_amount->senders as $wm_senders ) {
					        															        $total_shipping = $total_shipping + floatval($wm_senders->save);
					        														        }
					        														    }
					        														}															    
																				}
																			} else if ( floatval($data_shipping->cost_components->ratio) == 0 && floatval($data_shipping->cost_components->loyal_discount) > 0 && $total_shipping > 0 ) {
																				$por_discount_total = 1 - floatval($data_shipping->cost_components->loyal_discount);
																				$por_discount = floatval($data_shipping->cost_components->loyal_discount) * 100;
																				$full_por_discount = 100 - $por_discount;
																				if ( $full_por_discount != 0 ) {
																				    $total_shipping = $total_shipping + (round(($total_shipping * $por_discount) / $full_por_discount));
																			    }
																			} else {
					    														$data_shipping_gross_amount = WMeli::get_shipping( $data_shipping->id . '/costs', $wm_settings_page );
					    														if ( !empty($data_shipping_gross_amount) && isset($data_shipping_gross_amount->gross_amount) ) {
					    															$total_shipping = floatval($data_shipping_gross_amount->gross_amount);
					    															//$total_shipping = (-1) * $total_shipping;
					    														}														    
																			}
																		}
																		/*if ( $total_shipping == 0 && is_object($data_resource->payments) && isset($data_resource->payments->shipping_cost) ) {
																			$total_shipping = floatval($data_resource->payments->shipping_cost);
																		}*/
																	} else if ( isset($data_resource->payments) && !empty($data_resource->payments) ) {
																		foreach ( $data_resource->payments as $value_payments ) {
																			if ( is_object($value_payments) ) {
																				if ( isset($value_payments->status, $value_payments->shipping_cost) && $value_payments->status == "approved" ) {
																					$total_shipping = $total_shipping + floatval( $value_payments->shipping_cost );
																				}
																			}
																		}
																	}
																	$item_shipping->set_props( array(
																		'method_title' => $shipping_option_name,
																		'method_id'    => 0,
																		'total'        => $total_shipping,
																		'taxes'        => 0,
																	) );
																	$item_shipping->add_meta_data( 'shipmentid', $data_shipping->id, false );
																	$item_shipping->save();
																	$order->add_item( $item_shipping );
																}
															} else {
																wm_get_extension_order_address_buyer ( $data_resource, $meli_buyer, $wm_settings_page );
																$order->set_address( $meli_buyer, 'billing' );
															}
														}
														$order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
														if ( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') == $woocommerce_status ) {
															$order->set_total(0);	
														} else {
															$order->calculate_totals( $wm_settings_page->get_extension_order_woo_fee(true) );
														}
														$order->set_status( $woocommerce_status );
														$order->save();
														wm_set_market_on_wc( $order->get_id(), 'neighborhood', $neighborhood, $wm_settings_page );
														wm_set_market_on_wc( $order->get_id(), 'street_number', $street_number, $wm_settings_page );
														if ( !is_null($meli_doc_type) && $meli_doc_type != "" && !is_null($meli_billing_info) && $meli_billing_info != "" ) {
															$meli_doc_type_key = mb_strtolower( $meli_doc_type );
															wm_set_market_on_wc( $order->get_id(), 'doc_type_' . $meli_doc_type_key, $meli_billing_info, $wm_settings_page );
														}
														//bundle
														if ( $wm_woo_product == true ) {
															$wm_list_irder_items = $order->get_items();
															if ( !empty($wm_list_irder_items) && !empty($wm_woo_list_products) ) {
																$wm_woo_product_temp = $wm_woo_list_products[0];
																foreach ( $wm_list_irder_items as $item_id => $item ) {
																	$product_id_temp = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
																	if ( $product_id_temp != $wm_woo_product_temp->get_id() ) {
																		wc_add_order_item_meta( $item_id, '_woosb_parent_id', $wm_woo_product_temp->get_id() );
																	}
																}
															}
															unset( $wm_list_irder_items );
														}
														//bundle
														wm_update_meta_meta( $order->get_id(), '_wm_code_meli_order', $code, '', 'order' );
														wm_update_meta_meta( $order->get_id(), '_wm_sync_status_order', true, '', 'order' );
														//update_post_meta( $order->get_id(), '_wm_code_meli_order', $code );
														//update_post_meta( $order->get_id(), '_wm_sync_status_order', true );
														$wm_order = new WMOrder( $order->get_id() );
														$wm_order->set_woomelly_last_updated( $data_resource->last_updated );
														if ( is_object($data_shipping) ) {
															$wm_order->set_woomelly_shipping_last_updated( $data_shipping->last_updated );
														}
														if ( is_object($meli_billing_info_request) && isset($meli_billing_info_request->buyer) ) {
															$wm_order->set_meli_billing_info($meli_billing_info_request);
														}
														$wm_order->set_woomelly_code_meli_field( $code );
														$wm_order->set_woomelly_sync_status_field( "yes" );
														if ( $wm_order->get_woomelly_code_meli_field() != "" ) {
															$wm_order->set_woomelly_buyer( $data_resource->buyer->id );
															$wm_order->set_woomelly_payment_id( $wm_payment_id );
															$wm_order->set_woomelly_status_field( $woocommerce_status );
															$wm_order->set_woomelly_category_vertical( $meli_category_id );
															$wm_order->set_woomelly_manufacturing_ending_date( $manufacturing_ending_date );
															if ( isset($data_resource->context) ) {
																if ( isset($data_resource->context->channel) ) {
																	$wm_order->set_woomelly_channel( $data_resource->context->channel );
																}
																if ( isset($data_resource->context->flows) ) {
																	$wm_order->set_woomelly_flows( $data_resource->context->flows );
																}
															}
															if ( $wm_order->get_woomelly_shipping_status() != "shipped" && $wm_shipping_status == "shipped" ) {
																if ( wm_has_mediations($data_resource->mediations) == false && !in_array('shipping-sent', $wm_order->get_woomelly_messages()) ) {
																	$woomelly_get_message = new WMMessage();
																	$woomelly_get_message->send_message( false, 'shipping-sent', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																	$wm_order->set_woomelly_messages( 'shipping-sent' );
																}
															}
															$wm_order->set_woomelly_shipping_status( $wm_shipping_status );
															$data_resource_tags = array();
															if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
																$data_resource_tags = $data_resource->tags;
															}
															$wm_order->set_woomelly_tags( $data_resource_tags );
															unset( $data_resource_tags );
															$wm_order->set_woomelly_billing_info( array( 'doc_type' => $meli_doc_type, 'doc_number' => $meli_billing_info ) );
															$wm_buyer_email_aux = "";
															if ( isset($data_resource->buyer->email) ) {
																$wm_buyer_email_aux = $data_resource->buyer->email;
															}
															$wm_order->set_woomelly_email( filter_var($wm_buyer_email_aux, FILTER_SANITIZE_EMAIL) );
															if ( is_object($data_resource->status_detail) && isset($data_resource->status_detail->description) ) {
																$order->add_order_note( $data_resource->status_detail->description );
															}
															if ( is_object($data_resource->shipping) && isset($data_resource->shipping->id) && $data_resource->shipping->id != null ) {
																if ( is_object($data_shipping) ) {
																	if ( isset($data_shipping->id) && $data_shipping->id != "" ) {
																		$wm_order->set_woomelly_shipping_id( $data_shipping->id );
																	}									
																	if ( isset($data_shipping->tracking_method) && $data_shipping->tracking_method != "" ) {
																		$wm_order->set_woomelly_shipping_tracking_method( $data_shipping->tracking_method );
																	}
																	if ( isset($data_shipping->shipping_mode) && $data_shipping->shipping_mode!="" ) {
																		$wm_order->set_woomelly_shipping_mode( $data_shipping->shipping_mode );
																	} else if ( isset($data_shipping->mode) && $data_shipping->mode!="" ) {
																		$wm_order->set_woomelly_shipping_mode( $data_shipping->mode );
																	}
																	if ( is_object($data_shipping->shipping_option) && isset($data_shipping->shipping_option->id) ) {
																		$wm_order->set_woomelly_shipping_option_id( $data_shipping->shipping_option->id );
																	}
																	if ( isset($data_shipping->logistic_type) && $data_shipping->logistic_type != "" ) {
																		$wm_order->set_woomelly_shipping_logistic_type( $data_shipping->logistic_type );
																	} else if ( !isset($data_shipping->logistic_type) ) {
																		$wm_order->set_woomelly_shipping_logistic_type( 'custom' );													
																	}
																}
															}
															if ( $wm_settings_page->get_extension_order_reduce_inventory() == 'active' && $it_will_reduce_stock == true && $woocommerce_status != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') && $woocommerce_status != apply_filters('wm_filter_wc_status_failed', 'failed') ) {
																set_transient( '_wm_stop_reduce_stock', 'true', 10 );
																wc_reduce_stock_levels( $order->get_id() );
																//bundle
																if ( $wm_woo_product == true || $is_wc_bundle == true ) {
																	$wm_list_irder_items = $order->get_items();
																	if ( !empty($wm_list_irder_items) ) {
																		foreach ( $wm_list_irder_items as $item_id => $item ) {
																			wm_reduce_productwoo_bundle_stock($item->get_product(), $wm_settings_page);
																		}
																	}
																	unset( $wm_list_irder_items );
																}
																//bundle
															}
															//cart
																if ( $is_cart_order == true ) {
																	//$tags['{order_id}'] = sprintf('%.0f', $data_resource->pack_id);
																	$tags['{order_id}'] = $data_resource->pack_id;
																	//$wm_order->set_woomelly_cart_order_id(sprintf('%.0f', $data_resource->pack_id));
																	$wm_order->set_woomelly_cart_order_id( $data_resource->pack_id );
																	if ( $wm_order->get_woomelly_code_order_cart_parent() == "" ) {
																		$wm_order->set_woomelly_code_order_cart_parent($order->get_id());
																	}
																	if ( !in_array($data_resource->id, $wm_order->get_woomelly_code_order_cart()) ) {
																		$wm_order->set_woomelly_code_order_cart($data_resource->id);
																	}
																}
															//cart
															$status_now = '';
															if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																$status_now = $order->get_status();	
															} else {
																$status_now = $wm_order->get_woomelly_status_field();
															}
															$message_send = false;
															if ( $status_now != apply_filters('wm_filter_wc_status_failed', 'failed') && $status_now != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
																$data_resource_tags = array();
																if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
																	$data_resource_tags = $data_resource->tags;
																}
																$is_delivered = in_array( "delivered", $data_resource_tags );
																unset( $data_resource_tags );
																if ( $data_review == null ) $data_review = WMeli::get_orders( $code, 'feedback', $wm_settings_page );
																if ( (is_object($data_review) && isset($data_review->sale) && is_object($data_review->sale) && $data_review->sale!=null) || $is_delivered ) {
																	$wm_order->set_meli_feedback_info($data_review);
																	if ( (isset($data_review->sale->fulfilled) && $data_review->sale->fulfilled==true) || $is_delivered ) {
																		if ( $status_now != apply_filters('wm_filter_wc_status_completed', 'completed') ) {
																			if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																				$order->update_status( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			} else {
																				$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			}
																			if ( wm_has_mediations($data_resource->mediations) == false && !in_array('completed', $wm_order->get_woomelly_messages()) ) {
																				$woomelly_get_message = new WMMessage();
																				$woomelly_get_message->send_message( false, 'completed', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																				$message_send = true;
																				$wm_order->set_woomelly_messages( 'completed' );
																			}
																		}
																	} else if ( ($data_resource->status == 'confirmed' || $data_resource->status == 'paid' || $data_resource->status == 'cancelled' ) && $status_now != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
																		//$order->update_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																			$order->set_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																			$order->set_total(0);
																			$order->save();
																		} else {
																			$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		}
																		if ( wm_has_mediations($data_resource->mediations) == false && !in_array('cancelled', $wm_order->get_woomelly_messages()) ) {
																			$woomelly_get_message = new WMMessage();
																			$woomelly_get_message->send_message( false, 'cancelled', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																			$message_send = true;
																			$wm_order->set_woomelly_messages( 'cancelled' );
																		}
																	}
																} else {
																	if ( $status_now != apply_filters('wm_filter_wc_status_completed', 'completed') || ($status_now==apply_filters('wm_filter_wc_status_completed', 'completed') && $woocommerce_status==apply_filters('wm_filter_wc_status_failed', 'failed')) ) {
																		if ( $status_now != $woocommerce_status ) {
																			if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																				$order->update_status( $woocommerce_status, $notes, true );
																			} else {
																				$wm_order->set_woomelly_status_field( $woocommerce_status );
																			}
																			if ( wm_has_mediations($data_resource->mediations) == false && !in_array(apply_filters('wm_filter_wc_status_woocommerce', $woocommerce_status), $wm_order->get_woomelly_messages()) ) {
																				$woomelly_get_message = new WMMessage();
																				$woomelly_get_message->send_message( false, apply_filters('wm_filter_wc_status_woocommerce', $woocommerce_status), $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																				$message_send = true;
																				$wm_order->set_woomelly_messages( apply_filters('wm_filter_wc_status_woocommerce', $woocommerce_status) );
																			}
																		}											
																	}											
																}
																if ( $message_send == false && wm_has_mediations($data_resource->mediations) == false && !in_array(apply_filters('wm_filter_wc_status_woocommerce', $status_now), $wm_order->get_woomelly_messages()) ) {
																	$woomelly_get_message = new WMMessage();
																	$woomelly_get_message->send_message( false, apply_filters('wm_filter_wc_status_woocommerce', $status_now), $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																	$wm_order->set_woomelly_messages( apply_filters('wm_filter_wc_status_woocommerce', $status_now) );
																}
															} else {
																$data_resource_tags = array();
																if ( isset($data_resource->tags) && !empty($data_resource->tags) ) {
																	$data_resource_tags = $data_resource->tags;
																}													
																$is_delivered = in_array( "delivered", $data_resource_tags );
																unset( $data_resource_tags );
																if ( $data_review == null ) $data_review = WMeli::get_orders( $code, 'feedback', $wm_settings_page );
																if ( (is_object($data_review) && isset($data_review->sale) && is_object($data_review->sale) && $data_review->sale!=null) || $is_delivered ) {
																	$wm_order->set_meli_feedback_info($data_review);
																	if ( (isset($data_review->sale->fulfilled) && $data_review->sale->fulfilled==true) || $is_delivered ) {
																		if ( $status_now != apply_filters('wm_filter_wc_status_completed', 'completed') ) {
																			if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																				$order->update_status( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			} else {
																				$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_completed', 'completed') );
																			}													
																			if ( wm_has_mediations($data_resource->mediations) == false && !in_array('completed', $wm_order->get_woomelly_messages()) ) {
																				$woomelly_get_message = new WMMessage();
																				$woomelly_get_message->send_message( false, 'completed', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																				$wm_order->set_woomelly_messages( 'completed' );
																			}
																		}
																	} else if ( ($data_resource->status == 'confirmed' || $data_resource->status == 'paid' || $data_resource->status == 'cancelled' ) && $status_now != apply_filters('wm_filter_wc_status_cancelled', 'cancelled') ) {
																		//$order->update_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		if ( $wm_settings_page->get_extension_order_status() == 'active' ) {
																			$order->set_status( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																			$order->set_total(0);
																			$order->save();
																		} else {
																			$wm_order->set_woomelly_status_field( apply_filters('wm_filter_wc_status_cancelled', 'cancelled') );
																		}	
																		if ( wm_has_mediations($data_resource->mediations) == false && !in_array('cancelled', $wm_order->get_woomelly_messages()) ) {
																			$woomelly_get_message = new WMMessage();
																			$woomelly_get_message->send_message( false, 'cancelled', $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																			$wm_order->set_woomelly_messages( 'cancelled' );
																		}
																	}
																} else if ( wm_has_mediations($data_resource->mediations) == false && !in_array(apply_filters('wm_filter_wc_status_woocommerce', $status_now), $wm_order->get_woomelly_messages()) ) {
																	$woomelly_get_message = new WMMessage();
																	$woomelly_get_message->send_message( false, apply_filters('wm_filter_wc_status_woocommerce', $status_now), $tags, $order, $wm_order, $list_woo_products, $data_resource, $wm_settings_page );
																	$wm_order->set_woomelly_messages( apply_filters('wm_filter_wc_status_woocommerce', $status_now) );
																}
															}
															wc_delete_shop_order_transients( $order );
															$wpdb->query('COMMIT');
														} else {
															WMlog::set_log( sprintf('%s | %s: There was an unknown error with the order %s. Please try again and if the error persists, contact technical support.', __FUNCTION__, __METHOD__, $code), 'error' );
															$wpdb->query('ROLLBACK');
														}
													} catch ( \Exception $exception ) {
														WMlog::set_log( sprintf('%s | %s: There was an unknown error with the order %s. Please try again and if the error persists, contact technical support.', __FUNCTION__, __METHOD__, $code), 'error' );
														$wpdb->query('ROLLBACK');
													} catch ( \ErrorException $exception ) {
														WMlog::set_log( sprintf('%s | %s: There was an unknown error with the order %s. Please try again and if the error persists, contact technical support.', __FUNCTION__, __METHOD__, $code), 'error' );
														$wpdb->query('ROLLBACK');
													}
												}
											}
											if ( $data_resource->currency_id == "VES" ) {
												if ( is_plugin_active('woocommerce-currency-switcher/index.php') ) {
													$wm_full_unit_price = 0;
													$wm_unit_price = 0;
													if ( !empty($data_resource->order_items) ) {
														foreach ( $data_resource->order_items as $value ) {
															$wm_full_unit_price = floatval( $value->full_unit_price );
															$wm_unit_price = floatval( $value->unit_price );
														}
													}
													if ( $wm_full_unit_price > 0 && $wm_unit_price > 0 ) {
														wm_update_meta_meta( $wm_order->get_id(), '_woocs_order_rate', wc_format_decimal( ($wm_unit_price / $wm_full_unit_price), wc_get_price_decimals() ), '', 'order' );
														//update_post_meta( $wm_order->get_id(), '_woocs_order_rate', wc_format_decimal( ($wm_unit_price / $wm_full_unit_price), wc_get_price_decimals() ) );
													}
												}
											}
											do_action( 'woomelly_after_notification_wc_order', $data_resource, $wm_order );
											//notes
						                        if ( !is_null($order) && is_object($wm_order) ) {
							                        $my_notes = $wm_order->get_woomelly_notes_field();
							                        $code_notes = '';
							                        if ( $is_cart_order == true ) {
														$code_notes = $wm_order->get_woomelly_cart_order_id();
							                        } else {
														$code_notes = $code;
							                        }
							                        $data_notes = WMeli::get_orders( $code_notes, 'notes', $wm_settings_page );
							                        if ( !empty($data_notes) ) {
							                            foreach ( $data_notes as $notes_orders ) {
							                                if ( $notes_orders->order_id == $code_notes && !empty($notes_orders->results) ) {
							                                    foreach ( $notes_orders->results as $note ) {
							                                        if ( !in_array($note->id, $my_notes) ) {
							                                            $order->add_order_note( sprintf(__('"%s" from MercadoLibre', 'woomelly'), $note->note) );
							                                            $wm_order->set_woomelly_notes_field( $note->id );
							                                        }
							                                    }
							                                }
							                            }
							                        }
						                        }
					                        //notes
										}
									} else {
										WMlog::set_log( __("The product is not connected with woomelly: ", "woomelly") . serialize($data_resource->order_items), 'error' );
									}
								} else {
									WMlog::set_log( $date_created, 'error' );
								}
							}
						} else {
							//WMlog::set_log( 'NO: replicate orders - ' . $data_resource->id, 'error' );								
							// WMlog::set_log( 'Replicate orders is skipped by hook.', 'error' );
						}
						if ( $settings_extensions['feedback'] && $force !== 3 && $force !== 5 ) {
							//WMlog::set_log( 'YES: replicate feedbacks - ' . $data_resource->id, 'error' );
							if ( is_object($data_resource->feedback) ) {
								if ( !empty($data_resource->order_items) ) {
									foreach ( $data_resource->order_items as $value ) {
										$wm_product = null;
										$woo_product = null;
										if ( isset($value->item->variation_id) && $value->item->variation_id!="" ) {
											$wm_product = wm_get_product_by_code( $value->item->variation_id, false );
											if ( $wm_product == null ) {
												$wm_product = wm_get_product_by_code( $value->item->id );	
											}
										} else {
											$wm_product = wm_get_product_by_code( $value->item->id );
										}
										if ( $wm_product != null ) {
											$woo_product_temp = wc_get_product( $wm_product->get_id() );
											if ( $woo_product_temp->is_type( 'variation' ) ) {
												$woo_product = wc_get_product( $woo_product_temp->get_parent_id() );
											} else {
												$woo_product = $woo_product_temp;
											}
											if ( is_object($woo_product) && $woo_product->get_status() != "trash" ) {
												$list_woo_products_reviews[] = $woo_product;
												$all_products_is_ok = true;
											} else {
												$all_products_is_ok = false;
												break;								
											}
										} else {
											$all_products_is_ok = false;
											break;
										}
										unset( $wm_product );
										unset( $woo_product );
									}
								}
								if ( $all_products_is_ok == true && !empty($list_woo_products_reviews) ) {
									if ( !empty($data_resource) && is_object($data_resource) ) {
										if ( isset($data_resource->feedback) && ( isset($data_resource->feedback->buyer) || isset($data_resource->feedback->seller) ) ) {
											global $wpdb;
											$review_text = "";
											if ( $data_review == null ) $data_review = WMeli::get_orders( $code, 'feedback', $wm_settings_page );
											if ( is_object($data_review) && isset($data_review->purchase) && isset($data_review->purchase->id) ) {
												$wm_order->set_meli_feedback_info($data_review);
												if ( isset($data_review->purchase->rating) && !is_null($data_review->purchase->rating) && $data_review->purchase->rating != "" ) {
													if ( !is_null($data_review->purchase->id) && $data_review->purchase->id != "" ) {
														if ( $data_review->purchase->message != "" ) {
															$review_text = $data_review->purchase->message;
														}
														if ( $review_text == "" ) {
															switch ( $data_review->purchase->rating ) {
																case 'negative':
																	$review_text = apply_filters( 'wm_string_bad_review', sprintf( __("Bad Review | Review from MercadoLibre %s", "woomelly"), $wm_settings_page->get_permalink() ) );
																break;
																case 'neutral':
																	$review_text = apply_filters( 'wm_string_neutral_review', sprintf( __("Neutral Review | Review from MercadoLibre %s", "woomelly"), $wm_settings_page->get_permalink() ) );
																break;
																default:
																	$review_text = apply_filters( 'wm_string_success_review', sprintf( __("Success Review | Review from MercadoLibre %s", "woomelly"), $wm_settings_page->get_permalink() ) );
																break;
															}
														}
														$review = $wpdb->get_row( "SELECT comment_id FROM ". $wpdb->prefix ."commentmeta WHERE meta_key = 'purchase_id' AND meta_value = '".$data_review->purchase->id."'" );
														if ( $review ) {
															if ( isset($data_review->purchase->fulfilled) && $data_review->purchase->fulfilled ) {
																update_comment_meta( $review->comment_id, 'fulfilled', true );
															} else {
																update_comment_meta( $review->comment_id, 'fulfilled', false );
															}
															switch ( $data_review->purchase->rating ) {
																case 'negative':
																	update_comment_meta( $review->comment_id, 'rating', '1' );
																break;
																case 'neutral':
																	update_comment_meta( $review->comment_id, 'rating', '3' );
																break;
																default:
																	update_comment_meta( $review->comment_id, 'rating', '5' );
																break;
															}
															wp_update_comment( array( 'comment_ID' => $review->comment_id, 'comment_content' => $review_text ) );
														} else {
															if ( !isset($data_resource->buyer) || !isset($data_resource->buyer->first_name) ) {
																unset( $data_resource );
																$data_resource = WMeli::get_resource( $resource, $wm_settings_page );
															}
															if ( is_object($data_resource) ) {
																unset( $value );
																$wm_buyer_email_aux = "";
																if ( isset($data_resource->buyer->email) ) {
																	$wm_buyer_email_aux = $data_resource->buyer->email;
																}
																foreach ( $list_woo_products_reviews as $value ) {
																	$data_review_save = array(
																		'comment_post_ID' => $value->get_id(),
																		'comment_author' => ucwords( mb_strtolower( $data_resource->buyer->first_name ) ).' '.ucwords( mb_strtolower( $data_resource->buyer->last_name ) ),
																		'comment_author_email' => filter_var($wm_buyer_email_aux, FILTER_SANITIZE_EMAIL),
																		'comment_author_url' => '',
																		'comment_content' => $review_text,
																		'comment_type' => 'review',
																		'comment_parent' => 0,
																		'user_id' => 0,
																		'comment_author_IP' => '',
																		'comment_agent' => 'Mercadolibre',
																		'comment_date' => current_time('mysql'),
																		//'comment_date' => $data_review->purchase->date_created,
																		'comment_approved' => 1,
																	);
																	$product_review_id = wp_insert_comment( $data_review_save );
																	if ( $product_review_id > 0 ) {
																		if ( isset($data_review->purchase->fulfilled) && $data_review->purchase->fulfilled ) {
																			update_comment_meta( $product_review_id, 'fulfilled', true );
																		} else {
																			update_comment_meta( $product_review_id, 'fulfilled', false );
																		}
																		switch ( $data_review->purchase->rating ) {
																			case 'negative':
																				update_comment_meta( $product_review_id, 'rating', intval( '1' ) );
																			break;
																			case 'neutral':
																				update_comment_meta( $product_review_id, 'rating', intval( '3' ) );
																			break;
																			default:
																				update_comment_meta( $product_review_id, 'rating', intval( '5' ) );
																			break;
																		}
																		update_comment_meta( $product_review_id, 'purchase_id', $data_review->purchase->id );
																		foreach ( $list_woo_products_reviews as $value ) {
																			$average = WC_Comments::get_average_rating_for_product( $value );
																			wm_update_meta_meta( $value->get_id(), '_wc_average_rating', $average, '', 'order' );
																			//update_post_meta( $value->get_id(), '_wc_average_rating', $average );
																			$counts = WC_Comments::get_rating_counts_for_product( $value );
																			wm_update_meta_meta( $value->get_id(), '_wc_rating_count', $counts, '', 'order' );
																			//update_post_meta( $value->get_id(), '_wc_rating_count', $counts );
																			$review_count = WC_Comments::get_review_count_for_product( $value );
																			wm_update_meta_meta( $value->get_id(), '_wc_review_count', $review_count, '', 'order' );
																			//update_post_meta( $value->get_id(), '_wc_review_count', $review_count );
																		}
																	}
																	unset( $data_review_save );
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						} else {
							//WMlog::set_log( 'NO: replicate feedbacks - ' . $data_resource->id, 'error' );
						}
					} else {
						// WMlog::set_log( $data_resource, 'error' );
					}
				} else {
					// WMlog::set_log( $data_resource, 'error' );
				}
			} else {
				// No data replication module is active
			}
		} else {
			//WMlog::set_log( "woomelly_alive_error_on_notification_orders", 'error' );
		}
	} //End woomelly_notification_orders()

	/**
	 * @return
	 */
	public static function woomelly_notification_qandas ( $resource, $received ) {
		global $wm_all_settings;
		$data_resource 						= array();
		$woomelly_alive 					= Woomelly()->woomelly_is_connect( $wm_all_settings );
		if ( $woomelly_alive ) {
			$data_resource = WMeli::get_resource( $resource, $wm_all_settings );
			if ( is_object($data_resource) ) {
				if ( $data_resource->status != "BANNED" && $data_resource->status != "DELETED" ) {
					$wm_product = wm_get_product_by_code( $data_resource->item_id );
					if ( $wm_product != null ) {
						$parent = $wm_product->get_id();
						$wc_product = wc_get_product( $wm_product->get_id() );
						if ( is_object($wc_product) ) {
							$parent = $wc_product->get_parent_id();
							if ( $parent <= 0 ) {
								$parent = $wc_product->get_id();
							}
						}
						$wm_qanda = wm_get_qand_by_question_id( $data_resource->id );
						if ( $wm_qanda != false ) {
							if ( isset($data_resource->answer) )
								$wm_qanda->set_answer( $data_resource->answer );
							if ( isset($data_resource->deleted_from_listing) )
								$wm_qanda->set_deleted_from_listing( $data_resource->deleted_from_listing );
							if ( isset($data_resource->hold) )
								$wm_qanda->set_hold( $data_resource->hold );
							if ( isset($data_resource->status) )
								$wm_qanda->set_status( $data_resource->status );
							if ( isset($data_resource->text) )
								$wm_qanda->set_text( $data_resource->text );
							if ( isset($data_resource->from) )
								$wm_qanda->set_from_user( $data_resource->from );
							$wm_qanda->set_connect_ml( true );
							$save_qanda = $wm_qanda->update();
						} else {
							unset( $wm_qanda );
							$wm_qanda = new WMQandA();
							$wm_qanda->set_question_id( $data_resource->id );
							if ( isset($data_resource->answer) )
								$wm_qanda->set_answer( $data_resource->answer );
							if ( isset($data_resource->date_created) )
								$wm_qanda->set_date_created( $data_resource->date_created );
							if ( isset($data_resource->deleted_from_listing) )
								$wm_qanda->set_deleted_from_listing( $data_resource->deleted_from_listing );
							if ( isset($data_resource->hold) )
								$wm_qanda->set_hold( $data_resource->hold );
							if ( isset($data_resource->item_id) )
								$wm_qanda->set_item_id( $data_resource->item_id );
							if ( isset($data_resource->seller_id) )
								$wm_qanda->set_seller_id( $data_resource->seller_id );
							if ( isset($data_resource->status) )
								$wm_qanda->set_status( $data_resource->status );
							if ( isset($data_resource->text) )
								$wm_qanda->set_text( $data_resource->text );
							if ( isset($data_resource->from) )
								$wm_qanda->set_from_user( $data_resource->from );
							$wm_qanda->set_product_id( $parent );
							if ( isset($data_resource->from) && isset($data_resource->from->id) ) {
							$data_user = WMeli::get_users( $data_resource->from->id, $wm_all_settings );
								if ( !empty($data_user) ) {
									$wm_qanda->set_from_extra( $data_user );
								}
							}
							$wm_qanda->set_connect_ml( true );
							$save_qanda = $wm_qanda->save();
						}
					}
				} else {
					WMlog::set_log( $data_resource, 'error' );
				}
			} else {
				WMlog::set_log( $data_resource, 'error' );
			}
		} else {
			WMlog::set_log( $woomelly_alive, 'error' );
		}
	} //End woomelly_notification_qandas()
}

WMNotification::init();

Youez - 2016 - github.com/yon3zu
LinuXploit