....................................../////.===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 : 104.19.154.92  /  Your IP : 216.73.216.47
Web Server : Apache
System : Linux lon12.onrocket.com 4.18.0-513.9.1.lve.el8.x86_64 #1 SMP Mon Dec 4 15:01:22 UTC 2023 x86_64
User : gd5hzp4 ( 1069)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/gd5hzp4/www/wp-content/plugins/woo-variation-swatches-pro/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/gd5hzp4/www/wp-content/plugins/woo-variation-swatches-pro/includes/functions.php
<?php

defined( 'ABSPATH' ) or die( 'Keep Silent' );

if ( ! function_exists( 'wvs_pro_cache_variation_ajax' ) ):
	function wvs_pro_cache_variation_ajax( $headers ) {

		global $wp_query;
		// phpcs:disable WordPress.Security.NonceVerification.Recommended
		/*if ( ! empty( $_GET['wc-ajax'] ) ) {
			$wp_query->set( 'wc-ajax', sanitize_text_field( wp_unslash( $_GET['wc-ajax'] ) ) );
		}*/
		$action = $wp_query->get( 'wc-ajax' );
		$action = $action ? sanitize_text_field( $action ) : '';

		if ( in_array( $action, array( 'get_variations' ), true ) ) {
			$expires                  = gmdate( 'D, d M Y H:i:s T', current_time( 'timestamp' ) + DAY_IN_SECONDS );
			$cache_control            = sprintf( "public, max-age=%d", DAY_IN_SECONDS );
			$headers['Expires']       = $expires;
			$headers['Cache-Control'] = $cache_control;
			$headers['Pragma']        = 'cache'; //  backwards compatibility with HTTP/1.0 caches
		}

		return $headers;
	}
endif;

add_action( 'init', function () {
	add_filter( 'nocache_headers', 'wvs_pro_cache_variation_ajax' );
} );

// Ajax request of non ajax variation
if ( ! function_exists( 'wvs_pro_get_available_variations' ) ):
	function wvs_pro_get_available_variations() {

		ob_start();

		if ( empty( $_GET ) || empty( $_GET['product_id'] ) ) {
			wp_send_json( false );
		}

		$product_id     = absint( $_GET['product_id'] );
		$use_transient  = wc_string_to_bool( woo_variation_swatches()->get_option( 'use_transient' ) );
		$transient_name = sprintf( 'wvs_archive_available_variations_%s', $product_id );
		$cache          = new Woo_Variation_Swatches_Cache( $transient_name, 'wvs_archive_template' );

		// Clear cache
		if ( isset( $_GET['wvs_clear_transient'] ) ) {
			$cache->delete_transient();
		}

		// Create cache
		if ( $use_transient && $transient_data = $cache->get_transient( $transient_name ) ) {

			if ( ! empty( $transient_data ) ) {
				wp_send_json( $transient_data );
			}
		}

		$variable_product = wc_get_product( $product_id );

		if ( ! $variable_product ) {
			wp_send_json( false );
		}

		$data = apply_filters( 'wvs_pro_get_available_variations', array_values( $variable_product->get_available_variations() ), $variable_product );
		// Set cache
		if ( $use_transient ) {
			$cache->set_transient( $data, DAY_IN_SECONDS );
		}

		wp_send_json( $data ? $data : false );
	}
endif;

// Get Pro Product Option
if ( ! function_exists( 'wvs_pro_get_product_option' ) ):
	function wvs_pro_get_product_option( $product_id, $option_name = false ) {

		$options = (array) get_post_meta( $product_id, '_wvs_product_attributes', true );

		// $options = wvs_wpml_translate_options( $options );

		if ( ! $option_name ) {
			return $options;
		}

		if ( isset( $options[ $option_name ] ) ) {
			return $options[ $option_name ];
		}

		return null;
	}
endif;

// WPML Translate Options
if ( ! function_exists( 'wvs_wpml_translate_options' ) ) {
	function wvs_wpml_translate_options( $value ) {
		foreach ( (array) $value as $slug => $data ) {
			if ( isset( $value[ $slug ]['terms'] ) ) {
				$value[ $slug ]['terms'] = wvs_wpml_translate_terms( $slug, $data['terms'] );
			}
		}

		return $value;
	}
}

// WPML Translate Terms Data
if ( ! function_exists( 'wvs_wpml_translate_terms' ) ) {
	function wvs_wpml_translate_terms( $slug, $terms ) {
		$out = array();
		foreach ( (array) $terms as $term_id => $term ) {
			if ( ! empty( $term['image_id'] ) && $term['type'] == 'image' ) {
				$term['image_id'] = apply_filters( 'wpml_object_id', $term['image_id'], 'attachment', true );
			}
			$term_id         = apply_filters( 'wpml_object_id', $term_id, $slug, true );
			$out[ $term_id ] = $term;
		}

		return $out;
	}
}

// Radio Attribute Type
if ( ! function_exists( 'wvs_pro_radio_attribute_type' ) ) :
	function wvs_pro_radio_attribute_type( $types ) {
		$types['radio'] = array(
			'title'   => esc_html__( 'Radio', 'woo-variation-swatches-pro' ),
			'output'  => 'wvs_radio_variation_attribute_options',
			'preview' => 'wvs_radio_variation_attribute_preview'
		);

		return $types;
	}
endif;

// Add to cart ajax function
if ( ! function_exists( 'wvs_pro_add_to_cart' ) ):
	function wvs_pro_add_to_cart() {

		ob_start();

		$product_id        = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_POST['product_id'] ) );
		$product           = wc_get_product( $product_id );
		$quantity          = empty( $_POST['quantity'] ) ? 1 : wc_stock_amount( $_POST['quantity'] );
		$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
		$product_status    = get_post_status( $product_id );
		$variation_id      = absint( $_POST['variation_id'] );
		$variation         = $_POST['variation'];

		// If Not a variation
		if ( 'variable' != $product->get_type() || empty( $variation_id ) ) {
			// If there was an error adding to the cart, redirect to the product page to show any errors
			$data = array(
				'error'       => true,
				'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id ),
			);

			wp_send_json( $data );
		}

		if ( $passed_validation && false !== WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation ) && 'publish' === $product_status ) {

			do_action( 'woocommerce_ajax_added_to_cart', $product_id );

			if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
				wc_add_to_cart_message( array( $product_id => $quantity ), true );
			}

			// Return fragments
			WC_AJAX::get_refreshed_fragments();

		} else {

			// If there was an error adding to the cart, redirect to the product page to show any errors
			$data = array(
				'error'       => true,
				'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id ),
			);

			wp_send_json( $data );
		}
	}
endif;

// Loop cart arguments
if ( ! function_exists( 'wvs_pro_loop_add_to_cart_args' ) ):
	function wvs_pro_loop_add_to_cart_args( $args, $product ) {

		// return $args;

		if ( $product->is_type( 'variable' ) ) {

			if ( ! woo_variation_swatches()->get_option( 'show_on_archive' ) ) {
				return $args;
			}

			// $get_variations = count( $product->get_children() ) <= apply_filters( 'woocommerce_ajax_variation_threshold', 30, $product );

			$enable_catalog_mode = wc_string_to_bool( woo_variation_swatches()->get_option( 'enable_catalog_mode' ) );

			if ( ! isset( $args['class'] ) ) {
				$args['class'] = '';
			}
			if ( ! $enable_catalog_mode ) {
				$args['class'] .= ' wvs_add_to_cart_button';
			}

			// Based On WooCommerce Settings

			if ( ! isset( $args['attributes'] ) ) {
				$args['attributes'] = array();
			}

			// Borrow some methods from simple product
			$classname         = WC_Product_Factory::get_classname_from_product_type( 'simple' );
			$as_single_product = new $classname( $product->get_id() );

			if ( isset( $args['attributes']['aria-label'] ) ) {
				$args['attributes']['data-add-to-cart-aria-label']    = wp_strip_all_tags( $as_single_product->add_to_cart_description() );
				$args['attributes']['data-select-options-aria-label'] = wp_strip_all_tags( $args['attributes']['aria-label'] );
			}

			$args['attributes']['data-add-to-cart']    = wc_esc_json( wp_kses_post( apply_filters( 'woo_variation_swatches_archive_add_to_cart_text', apply_filters( 'woo_variation_swatches_archive_add_to_cart_button_text', apply_filters( 'add_to_cart_text', $as_single_product->add_to_cart_text() ), $product ), $product, $as_single_product ) ) );
			$args['attributes']['data-select-options'] = wc_esc_json( wp_kses_post( apply_filters( 'woo_variation_swatches_archive_add_to_cart_select_options', apply_filters( 'woo_variation_swatches_archive_add_to_cart_button_text', apply_filters( 'variable_add_to_cart_text', $product->add_to_cart_text() ), $product ), $product, $as_single_product ) ) );

			if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) && ! $enable_catalog_mode ) {
				$args['class'] .= ' wvs_ajax_add_to_cart';
			} else {
				$args['attributes']['data-product_permalink'] = $product->add_to_cart_url();
				// $args[ 'attributes' ][ 'data-add_to_cart_url' ]   = $product->is_purchasable() && $product->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( 'add-to-cart', $product->get_id() ) ) : get_permalink( $product->get_id() );
				$args['attributes']['data-add_to_cart_url'] = $product->is_purchasable() && $product->is_in_stock() ? wvs_pro_get_current_url() : esc_url( $product->get_permalink() );
			}

			// variation_id
			$args['attributes']['data-variation_id'] = "";
			$args['attributes']['data-variation']    = "";

			/*$args['variations'] = array(
				'available_variations' => $get_variations ? array_values( $product->get_available_variations() ) : false,
				'attributes'           => $product->get_variation_attributes(),
				'selected_attributes'  => $product->get_default_attributes(),
			);*/
		}

		return $args;
	}
endif;

// Add to cart link
if ( ! function_exists( 'wvs_pro_loop_add_to_cart_link' ) ):
	function wvs_pro_loop_add_to_cart_link( $link, $product ) {
		echo $link;

		if ( apply_filters( 'wvs_pro_use_add_to_cart_link_archive_template', true, $product ) ) {
			wvs_pro_archive_variation_template();
		}
	}
endif;

// Add to cart options
if ( ! function_exists( 'wvs_pro_loop_add_to_cart_options' ) ):
	function wvs_pro_loop_add_to_cart_options( $args = array() ) {
		global $product;

		if ( $product ) {
			$defaults = array(
				'quantity'   => 1,
				'class'      => implode(
					' ', array_filter(
						array(
							'button',
							'product_type_' . $product->get_type(),
							$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
							$product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
						)
					)
				),
				'attributes' => array(
					'data-product_id'  => $product->get_id(),
					'data-product_sku' => $product->get_sku(),
					'aria-label'       => wp_strip_all_tags( $product->add_to_cart_description() ),
					'rel'              => 'nofollow',
				),
			);

			return apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
		}

		return false;
	}
endif;

// Archive Variation Template
if ( ! function_exists( 'wvs_pro_archive_variation_template' ) ):
	function wvs_pro_archive_variation_template( $args = array() ) {
		global $product;

		if ( ! $product ) {
			return;
		}

		if ( ! woo_variation_swatches()->get_option( 'show_on_archive' ) ) {
			return;
		}

		// $product->is_type( 'variable' ) == variable | variation
		do_action( 'before_wvs_pro_archive_variation_template_load', $product );
		if ( $product->is_type( 'variable' ) && apply_filters( 'wvs_pro_show_archive_variation_template', true, $product ) ) {

			$available_variations = $product->get_available_variations();
			if ( empty( $available_variations ) && false !== $available_variations ) {
				return;
			}

			// $options = wvs_pro_loop_add_to_cart_options( $args );

			// Enqueue variation scripts.
			wp_enqueue_script( 'wc-add-to-cart-variation' );

			wc_get_template( 'wvs-archive-variation.php', compact( 'product' ), '', trailingslashit( woo_variation_swatches_pro()->template_path() ) );
		}
		do_action( 'after_wvs_pro_archive_variation_template_load', $product );
	}
endif;

// Product loop post class
if ( ! function_exists( 'wvs_pro_product_loop_post_class' ) ):
	function wvs_pro_product_loop_post_class( $classes, $class, $product_id ) {

		if ( apply_filters( 'disable_wvs_pro_post_class', false, $product_id ) ) {
			return $classes;
		}

		if ( 'product' === get_post_type( $product_id ) ) {
			$product = wc_get_product( $product_id );
			if ( $product->is_type( 'variable' ) ) {
				$classes[] = 'wvs-pro-product';
				$classes[] = sprintf( 'wvs-pro-%s-cart-button', woo_variation_swatches()->get_option( 'archive_swatches_position' ) );
			}
		}

		return array_unique( $classes );
	}
endif;

if ( ! function_exists( 'wvs_pro_wc_product_loop_post_class' ) ):
	function wvs_pro_wc_product_loop_post_class( $classes, $product ) {

		if ( apply_filters( 'disable_wvs_pro_post_class', false, $product ) ) {
			return $classes;
		}

		if ( $product->is_type( 'variable' ) ) {
			$classes[] = 'wvs-pro-product';
			$classes[] = sprintf( 'wvs-pro-%s-cart-button', woo_variation_swatches()->get_option( 'archive_swatches_position' ) );
		}

		return array_unique( $classes );
	}
endif;

// Change script data
if ( ! function_exists( 'wvs_pro_wc_get_script_data' ) ):
	function wvs_pro_wc_get_script_data( $params, $handle ) {
		if ( 'wc-add-to-cart-variation' === $handle ) {
			$params = array_merge(
				$params, array(
					'ajax_url'                => WC()->ajax_url(),
					'i18n_view_cart'          => apply_filters( 'wvs_pro_view_cart_text', esc_attr__( 'View cart', 'woocommerce' ) ),
					'i18n_add_to_cart'        => apply_filters( 'wvs_pro_add_to_cart_text', esc_attr__( 'Add to cart', 'woocommerce' ) ),
					'i18n_select_options'     => apply_filters( 'wvs_pro_select_options_text', esc_attr__( 'Select options', 'woocommerce' ) ),
					'cart_url'                => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url(), null ),
					'is_cart'                 => is_cart(),
					'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),
					'enable_ajax_add_to_cart' => get_option( 'woocommerce_enable_ajax_add_to_cart' )
				)
			);

			wc_get_template( 'wvs-variation-template.php', array(), '', trailingslashit( woo_variation_swatches_pro()->template_path() ) );
		}

		return $params;
	}
endif;

// Get Current URL
if ( ! function_exists( 'wvs_pro_get_current_url' ) ):
	function wvs_pro_get_current_url( $args = array() ) {
		global $wp;

		return esc_url( trailingslashit( home_url( add_query_arg( $args, $wp->request ) ) ) );
	}
endif;

// Simple Product Add To Cart URL Fix
if ( ! function_exists( 'wvs_simple_product_cart_url' ) ):
	function wvs_simple_product_cart_url( $url, $product ) {

		if ( 'simple' === $product->get_type() ) {
			$url = $product->is_purchasable() && $product->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( 'add-to-cart', $product->get_id(), wvs_pro_get_current_url() ) ) : get_permalink( $product->get_id() );
		}

		return $url;
	}
endif;

// Attribute select-box
if ( ! function_exists( 'wvs_pro_variation_attribute_options' ) ):
	function wvs_pro_variation_attribute_options( $args = array(), $hide_select = true ) {

		$args = wp_parse_args(
			$args, array(
				'options'          => false,
				'attribute'        => false,
				'product'          => false,
				'selected'         => false,
				'name'             => '',
				'id'               => '',
				'class'            => '',
				'type'             => '',
				'show_option_none' => esc_html__( 'Choose an option', 'woo-variation-swatches-pro' )
			)
		);

		$type                  = $args['type'];
		$options               = $args['options'];
		$product               = $args['product'];
		$attribute             = $args['attribute'];
		$name                  = $args['name'] ? $args['name'] : wc_variation_attribute_name( $attribute );
		$id                    = $args['id'] ? $args['id'] : sanitize_title( $attribute );
		$class                 = $args['class'];
		$show_option_none      = $args['show_option_none'] ? true : false;
		$show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : esc_html__( 'Choose an option', 'woocommerce' ); // We'll do our best to hide the placeholder, but we'll need to show something when resetting options.

		if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
			$attributes = $product->get_variation_attributes();
			$options    = $attributes[ $attribute ];
		}

		if ( $product && $hide_select ) {
			echo '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . ' wvs-saved-attrs hide woo-variation-raw-select woo-variation-raw-type-' . esc_attr( $type ) . '" style="display:none" name="' . esc_attr( $name ) . '" data-attribute_name="' . esc_attr( wc_variation_attribute_name( $attribute ) ) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
		} else {
			echo '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . ' wvs-saved-attrs" name="' . esc_attr( $name ) . '" data-attribute_name="' . esc_attr( wc_variation_attribute_name( $attribute ) ) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
		}

		if ( $args['show_option_none'] ) {
			echo '<option value="">' . esc_html( $show_option_none_text ) . '</option>';
		}

		if ( ! empty( $options ) ) {
			if ( $product && taxonomy_exists( $attribute ) ) {
				// Get terms if this is a taxonomy - ordered. We need the names too.
				$terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );

				foreach ( $terms as $term ) {
					if ( in_array( $term->slug, $options, true ) ) {
						echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $attribute, $product ) . '</option>';
					}
				}
			} else {
				foreach ( $options as $option ) {
					// This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
					$selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
					echo '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option, null, $attribute, $product ) ) . '</option>';
				}
			}
		}

		echo '</select>';
	}
endif;


if ( ! function_exists( 'wvs_archive_swatches_has_more' ) ):
	function wvs_archive_swatches_has_more( $count ) {

		$limit        = absint( woo_variation_swatches()->get_option( 'catalog_mode_display_limit' ) );
		$catalog_mode = (bool) woo_variation_swatches()->get_option( 'enable_catalog_mode' );

		if ( empty( $limit ) || empty( $catalog_mode ) ) {
			return false;
		}

		return $limit <= $count;
	}
endif;


if ( ! function_exists( 'wvs_archive_swatches_more' ) ):
	function wvs_archive_swatches_more( $product_id, $total_items ) {

		$limit      = absint( woo_variation_swatches()->get_option( 'catalog_mode_display_limit' ) );
		$rest_items = absint( $total_items ) - $limit;
		$more_text  = sprintf( esc_html__( '+%s More', 'woo-variation-swatches-pro' ), number_format_i18n( $rest_items ) );

		$data = '<li class="woo-variation-swatches-variable-item-more">';
		$data .= sprintf( '<a style="font-size: small" href="%s">%s</a>', esc_url( get_permalink( $product_id ) ), $more_text );
		$data .= '</li>';

		return $data;
	}
endif;

// Default WooCommerce Image Class .wp-post-image
function wvs_add_default_archive_image_class( $image ) {
	$pattern  = '@class=["|\']([^"\']+)["|\']@i';
	$is_match = (bool) preg_match( $pattern, $image, $matches );

	if ( $is_match && isset( $matches[1] ) && $matches[1] ) {
		$class   = trim( $matches[1] );
		$classes = (array) explode( ' ', $class );
		array_push( $classes, 'wp-post-image' );
		$classes = implode( ' ', array_unique( $classes ) );

		$image = str_ireplace( $class, $classes, $image );
	}

	return $image;
}

function wvs_add_default_attachment_image_class( $attr ) {
	if ( ! is_admin() ) {

		$classes = (array) explode( ' ', $attr['class'] );

		array_push( $classes, 'wvs-attachment-image' );

		$attr['class'] = implode( ' ', array_unique( $classes ) );
	}


	return $attr;
}

// Function override
/*if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {

	function woocommerce_get_product_thumbnail( $size = 'woocommerce_thumbnail', $deprecated1 = 0, $deprecated2 = 0 ) {
		global $product;

		$image_size  = apply_filters( 'single_product_archive_thumbnail_size', $size );
		$image_class = "attachment-$image_size size-$image_size wp-post-image";

		return $product ? $product->get_image( $image_size, array( 'class' => $image_class ) ) : '';
	}
}*/

// Function override
function wvs_variable_item( $type, $options, $args, $saved_attribute = array() ) {

	$product              = $args['product'];
	$attribute            = $args['attribute'];
	$data                 = '';
	$is_archive           = ( isset( $args['is_archive'] ) && $args['is_archive'] );
	$show_archive_tooltip = (bool) woo_variation_swatches()->get_option( 'show_tooltip_on_archive' );
	$linkable_attribute   = ( (bool) woo_variation_swatches()->get_option( 'linkable_attribute' ) && ( woo_variation_swatches()->get_option( 'trigger_catalog_mode' ) == 'hover' ) );

	$product_url    = $product->get_permalink();
	$attribute_name = wc_variation_attribute_name( $attribute );

	if ( ! empty( $options ) ) {
		$name          = uniqid( wc_variation_attribute_name( $attribute ) );
		$display_count = 0;

		if ( $product && taxonomy_exists( $attribute ) ) {

			$terms       = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
			$total_terms = count( $terms );
			foreach ( $terms as $term ) {
				if ( in_array( $term->slug, $options, true ) ) {

					$term_id = $term->term_id;

					$type = isset( $saved_attribute['terms'][ $term_id ]['type'] ) ? $saved_attribute['terms'][ $term_id ]['type'] : $type;

					$is_selected             = ( sanitize_title( $args['selected'] ) == $term->slug );
					$selected_class          = $is_selected ? 'selected' : '';
					$screen_reader_html_attr = $is_selected ? ' aria-checked="true"' : ' aria-checked="false"';
					$data_url                = '';
					if ( $linkable_attribute && $is_archive ) {
						$url      = esc_url( add_query_arg( $attribute_name, $term->slug, $product_url ) );
						$data_url = sprintf( ' data-url="%s"', $url );
					}

					// Tooltip
					// from attributes
					$default_tooltip_type = get_term_meta( $term_id, 'show_tooltip', true );
					$default_tooltip_type = empty( $default_tooltip_type ) ? 'text' : $default_tooltip_type;

					// from product attribute
					$default_tooltip_type = ( isset( $saved_attribute['show_tooltip'] ) && ! empty( $saved_attribute['show_tooltip'] ) ) ? $saved_attribute['show_tooltip'] : $default_tooltip_type;

					// from attribute
					$default_tooltip_text = trim( get_term_meta( $term_id, 'tooltip_text', true ) );
					// from attribute fallback
					$default_tooltip_text = empty( $default_tooltip_text ) ? trim( apply_filters( 'wvs_variable_item_tooltip', $term->name, $term, $args ) ) : $default_tooltip_text;

					// from attribute
					$default_tooltip_image = trim( get_term_meta( $term_id, 'tooltip_image', true ) );


					// from product attribute item
					$tooltip_type  = ( isset( $saved_attribute['terms'][ $term_id ] ) && ! empty( $saved_attribute['terms'][ $term_id ]['tooltip_type'] ) ) ? trim( $saved_attribute['terms'][ $term_id ]['tooltip_type'] ) : $default_tooltip_type;
					$tooltip_text  = ( isset( $saved_attribute['terms'][ $term_id ] ) && ! empty( $saved_attribute['terms'][ $term_id ]['tooltip_text'] ) ) ? trim( $saved_attribute['terms'][ $term_id ]['tooltip_text'] ) : $default_tooltip_text;
					$tooltip_image = ( isset( $saved_attribute['terms'][ $term_id ] ) && ! empty( $saved_attribute['terms'][ $term_id ]['tooltip_image'] ) ) ? trim( $saved_attribute['terms'][ $term_id ]['tooltip_image'] ) : $default_tooltip_image;

					// from product attribute item

					if ( isset( $saved_attribute['terms'][ $term_id ] ) && empty( $saved_attribute['terms'][ $term_id ]['tooltip_type'] ) ) {
						$tooltip_type = $default_tooltip_type;
						$tooltip_text = $default_tooltip_text;
					}

					$show_tooltip = ! empty( $tooltip_type ) || $tooltip_type !== 'no';

					if ( $is_archive ) {
						$show_tooltip = $show_archive_tooltip;
					}

					$tooltip_html_attr = '';
					$tooltip_html_attr .= ( $show_tooltip && $tooltip_text && $tooltip_type == 'text' ) ? sprintf( ' data-wvstooltip="%s"', esc_attr( $tooltip_text ) ) : '';

					$tooltip_image_width = absint( woo_variation_swatches()->get_option( 'tooltip_image_width' ) );

					$tooltip_image_size = apply_filters( 'wvs_tooltip_image_size', array(
						$tooltip_image_width,
						$tooltip_image_width
					) );
					// $tooltip_image_width = apply_filters( 'wvs_tooltip_image_width', sprintf( '%dpx', $tooltip_image_width ) );

					$tooltip_html_image = ( $show_tooltip && $tooltip_type == 'image' && $tooltip_image ) ? wp_get_attachment_image_src( $tooltip_image, $tooltip_image_size ) : false;

					if ( wp_is_mobile() ) {
						$tooltip_html_attr .= ( $show_tooltip ) ? ' tabindex="2"' : '';
					}

					// More...
					if ( $is_archive && wvs_archive_swatches_has_more( $display_count ) ) {
						$data .= wvs_archive_swatches_more( $product->get_id(), $total_terms );
						break;
					}

					if ( ! empty( $tooltip_html_image ) ):
						// $tooltip_html_attr .= sprintf( ' style="--tooltip-background: url(\'%s\'); --tooltip-width: %spx; --tooltip-height: %spx;"', $tooltip_html_image[ 0 ], $tooltip_html_image[ 1 ], $tooltip_html_image[ 2 ] );
						$tooltip_html_attr .= sprintf( ' style="--tooltip-background: url(\'%s\'); --tooltip-width: %spx; --tooltip-height: %spx;"', $tooltip_html_image[0], $tooltip_image_width, $tooltip_image_width );
						$selected_class    .= ' wvs-has-image-tooltip';
					endif;


					$data .= sprintf( '<li %1$s class="variable-item %2$s-variable-item %2$s-variable-item-%3$s %4$s" data-title="%5$s" title="%5$s" data-value="%3$s" role="radio" tabindex="0"><div class="variable-item-contents">', $data_url . $screen_reader_html_attr . $tooltip_html_attr, esc_attr( $type ), esc_attr( $term->slug ), esc_attr( $selected_class ), esc_html( $term->name ) );

					/*if ( ! empty( $tooltip_html_image ) ):
						$data .= '<span style="width: ' . $tooltip_image_width . '" class="image-tooltip-wrapper"><img alt="' . $term->name . '" src="' . $tooltip_html_image[ 0 ] . '" width="' . $tooltip_html_image[ 1 ] . '" height="' . $tooltip_html_image[ 2 ] . '" /></span>';
						// $data .= '<span style="width: ' . $tooltip_image_width . '" class="image-tooltip-wrapper">' . $tooltip_html_image . '</span>';
					endif;*/

					switch ( $type ):
						case 'color':
							$global_color           = sanitize_hex_color( get_term_meta( $term->term_id, 'product_attribute_color', true ) );
							$global_is_dual         = (bool) ( get_term_meta( $term->term_id, 'is_dual_color', true ) === 'yes' );
							$global_secondary_color = sanitize_hex_color( get_term_meta( $term->term_id, 'secondary_color', true ) );

							$color           = ( isset( $saved_attribute['terms'][ $term_id ] ) && ! empty( $saved_attribute['terms'][ $term_id ]['color'] ) ) ? $saved_attribute['terms'][ $term_id ]['color'] : $global_color;
							$is_dual         = ( isset( $saved_attribute['terms'][ $term_id ] ) && isset( $saved_attribute['terms'][ $term_id ]['is_dual_color'] ) && ( $saved_attribute['terms'][ $term_id ]['is_dual_color'] ) === 'yes' ) ? $saved_attribute['terms'][ $term_id ]['is_dual_color'] : $global_is_dual;
							$secondary_color = ( isset( $saved_attribute['terms'][ $term_id ] ) && ! empty( $saved_attribute['terms'][ $term_id ]['secondary_color'] ) ) ? $saved_attribute['terms'][ $term_id ]['secondary_color'] : $global_secondary_color;

							if ( $is_dual ) {
								$data .= sprintf( '<span class="variable-item-span variable-item-span-%1$s variable-item-span-dual-color" style="background: linear-gradient(-45deg, %2$s 0%%, %2$s 50%%, %3$s 50%%, %3$s 100%%);"></span>', esc_attr( $type ), esc_attr( $secondary_color ), esc_attr( $color ) );
							} else {
								$data .= sprintf( '<span class="variable-item-span variable-item-span-%s" style="background-color:%s;"></span>', esc_attr( $type ), esc_attr( $color ) );
							}

							break;

						case 'image':

							$global_attachment_id = apply_filters( 'wvs_product_global_attribute_image_id', absint( get_term_meta( $term->term_id, 'product_attribute_image', true ) ), $term, $args );

							$attachment_id = ( isset( $saved_attribute['terms'][ $term_id ] ) && ! empty( $saved_attribute['terms'][ $term_id ]['image_id'] ) ) ? $saved_attribute['terms'][ $term_id ]['image_id'] : $global_attachment_id;

							$global_image_size = woo_variation_swatches()->get_option( 'attribute_image_size' );

							$image_size = ( isset( $saved_attribute['image_size'] ) && ! empty( $saved_attribute['image_size'] ) ) ? $saved_attribute['image_size'] : $global_image_size;

							$image_html = wp_get_attachment_image_src( $attachment_id, apply_filters( 'wvs_product_attribute_image_size', $image_size, $attribute, $product ) );

							$data .= sprintf( '<img aria-hidden="true" alt="%s" src="%s" width="%d" height="%d" />', esc_attr( $term->name ), esc_url( $image_html[0] ), $image_html[1], $image_html[2] );

							break;

						case 'button':
							$data .= sprintf( '<span class="variable-item-span variable-item-span-%s">%s</span>', esc_attr( $type ), esc_html( $term->name ) );
							break;

						case 'radio':
							$id   = uniqid( $term->slug );
							$data .= sprintf( '<input name="%1$s" id="%2$s" class="wvs-radio-variable-item" %3$s  type="radio" value="%4$s" data-value="%4$s" /><label for="%2$s">%5$s</label>', $name, $id, checked( sanitize_title( $args['selected'] ), $term->slug, false ), esc_attr( $term->slug ), esc_html( $term->name ) );
							break;

						default:
							$data .= apply_filters( 'wvs_variable_default_item_content', '', $term, $args );
							break;
					endswitch;

					if ( (bool) woo_variation_swatches()->get_option( 'show_variation_stock_info' ) ) {
						$data .= '<span class="wvs-stock-left-info" data-wvs-stock-info=""></span>';
					}

					$data .= '</div></li>';

					$display_count ++;
				}
			}
		} else {
			// Custom Attributes

			$terms = ! empty( $saved_attribute['terms'] ) ? (array) $saved_attribute['terms'] : array();
			// $total_terms = count( $terms );
			$total_terms = count( $options );
			// foreach ( $terms as $term_id => $term )

			foreach ( $options as $option ) {

				$term_id = trim( $option );
				$term    = $terms[ $option ];

				$type = isset( $term['type'] ) ? $term['type'] : $saved_attribute['type'];

				$is_selected             = ( sanitize_title( $args['selected'] ) == $term_id );
				$selected_class          = $is_selected ? 'selected' : '';
				$screen_reader_html_attr = $is_selected ? ' aria-checked="true"' : ' aria-checked="false"';
				$data_url                = '';
				if ( $linkable_attribute && $is_archive ) {
					$url      = esc_url( add_query_arg( $attribute_name, $term_id, $product_url ) );
					$data_url = sprintf( ' data-url="%s"', $url );
				}
				// Tooltip

				$default_tooltip_type = ( isset( $saved_attribute['show_tooltip'] ) && ! empty( $saved_attribute['show_tooltip'] ) ) ? $saved_attribute['show_tooltip'] : 'text';
				$default_tooltip_text = trim( apply_filters( 'wvs_color_variable_item_tooltip', $term_id, $term, $args ) );

				// from product attribute item
				$tooltip_type = ( isset( $term['tooltip_type'] ) && ! empty( $term['tooltip_type'] ) ) ? trim( $term['tooltip_type'] ) : $default_tooltip_type;
				$tooltip_text = ( isset( $term['tooltip_text'] ) && ! empty( $term['tooltip_text'] ) ) ? trim( $term['tooltip_text'] ) : $default_tooltip_text;

				if ( isset( $term['tooltip_type'] ) && empty( $term['tooltip_type'] ) ) {
					$tooltip_type = $default_tooltip_type;
					$tooltip_text = $default_tooltip_text;
				}

				$tooltip_image = ( isset( $term['tooltip_image'] ) && ! empty( $term['tooltip_image'] ) ) ? trim( $term['tooltip_image'] ) : false;

				$show_tooltip = ! empty( $tooltip_type ) || $tooltip_type !== 'no';

				if ( $is_archive ) {
					$show_tooltip = $show_archive_tooltip;
				}

				$tooltip_html_attr = '';
				$tooltip_html_attr .= ( $show_tooltip && $tooltip_text && $tooltip_type == 'text' ) ? sprintf( ' data-wvstooltip="%s"', esc_attr( $tooltip_text ) ) : '';

				$tooltip_image_width = absint( woo_variation_swatches()->get_option( 'tooltip_image_width' ) );

				$tooltip_image_size = apply_filters( 'wvs_tooltip_image_size', array(
					$tooltip_image_width,
					$tooltip_image_width
				) );
				// $tooltip_image_width = apply_filters( 'wvs_tooltip_image_width', sprintf( '%dpx', $tooltip_image_width ) );

				//$tooltip_html_image = ( $show_tooltip && $tooltip_type == 'image' && $tooltip_image ) ? wp_get_attachment_image_url( $tooltip_image, $tooltip_image_size ) : false;
				$tooltip_html_image = ( $show_tooltip && $tooltip_type == 'image' && $tooltip_image ) ? wp_get_attachment_image_src( $tooltip_image, $tooltip_image_size ) : false;

				if ( wp_is_mobile() ) {
					$tooltip_html_attr .= ( $show_tooltip ) ? ' tabindex="2"' : '';
				}


				// More...
				if ( $is_archive && wvs_archive_swatches_has_more( $display_count ) ) {
					$data .= wvs_archive_swatches_more( $product->get_id(), $total_terms );
					break;
				}

				if ( ! empty( $tooltip_html_image ) ):
					// $tooltip_html_attr .= sprintf( ' style="--tooltip-background: url(\'%s\'); --tooltip-width: %spx; --tooltip-height: %spx;"', $tooltip_html_image[ 0 ], $tooltip_html_image[ 1 ], $tooltip_html_image[ 2 ] );
					$tooltip_html_attr .= sprintf( ' style="--tooltip-background: url(\'%s\'); --tooltip-width: %spx; --tooltip-height: %spx;"', $tooltip_html_image[0], $tooltip_image_width, $tooltip_image_width );
					$selected_class    .= ' wvs-has-image-tooltip';
				endif;

				$data .= sprintf( '<li %1$s class="variable-item %2$s-variable-item %2$s-variable-item-%3$s %4$s" data-title="%5$s" title="%5$s" data-value="%5$s"  role="radio" tabindex="0"><div class="variable-item-contents">', $data_url . $screen_reader_html_attr . $tooltip_html_attr, esc_attr( $type ), sanitize_title( $term_id ), esc_attr( $selected_class ), esc_html( $term_id ) );

				/*if ( ! empty( $tooltip_html_image ) ):
					$data .= '<span style="width: ' . $tooltip_image_width . '" class="image-tooltip-wrapper"><img alt="' . $term_id . '" src="' . $tooltip_html_image[ 0 ] . '" width="' . $tooltip_html_image[ 1 ] . '" height="' . $tooltip_html_image[ 2 ] . '" /></span>';
					// $data .= '<span style="width: ' . $tooltip_image_width . '" class="image-tooltip-wrapper">' . $tooltip_html_image . '</span>';
				endif;*/

				switch ( $type ):
					case 'color':

						$color           = $term['color'];
						$is_dual         = $term['is_dual_color'];
						$secondary_color = $term['secondary_color'];

						if ( $is_dual ) {
							$data .= sprintf( '<span class="variable-item-span variable-item-span-color variable-item-span-dual-color" style="background: linear-gradient(-45deg, %1$s 0%%, %1$s 50%%, %2$s 50%%, %2$s 100%%);"></span>', esc_attr( $secondary_color ), esc_attr( $color ) );
						} else {
							$data .= sprintf( '<span class="variable-item-span variable-item-span-color" style="background-color:%s;"></span>', esc_attr( $color ) );
						}
						break;

					case 'image':

						$attachment_id = $term['image_id'];

						$global_image_size = woo_variation_swatches()->get_option( 'attribute_image_size' );

						$image_size = ( isset( $saved_attribute['image_size'] ) && ! empty( $saved_attribute['image_size'] ) ) ? $saved_attribute['image_size'] : $global_image_size;

						$image_html = wp_get_attachment_image_src( $attachment_id, apply_filters( 'wvs_product_attribute_image_size', $image_size, $attribute, $product ) );

						$data .= sprintf( '<img aria-hidden="true" alt="%s" src="%s" width="%d" height="%d" />', esc_attr( $term_id ), esc_url( $image_html[0] ), $image_html[1], $image_html[2] );

						break;

					case 'button':
						$data .= sprintf( '<span class="variable-item-span variable-item-span-button">%s</span>', esc_html( $term_id ) );
						break;

					case 'radio':
						$id   = uniqid( sanitize_title( $term_id ) );
						$data .= sprintf( '<input name="%1$s" id="%2$s" class="wvs-radio-variable-item" %3$s type="radio" value="%4$s" data-value="%4$s" /><label for="%2$s">%5$s</label>', $name, $id, checked( sanitize_title( $args['selected'] ), $term_id, true ), esc_attr( $term_id ), esc_html( $term_id ) );
						break;

					default:
						$data .= apply_filters( 'wvs_variable_default_item_content', '', $term_id, $args );
						break;
				endswitch;

				if ( (bool) woo_variation_swatches()->get_option( 'show_variation_stock_info' ) ) {
					$data .= '<span class="wvs-stock-left-info" data-wvs-stock-info=""></span>';
				}

				$data .= '</div></li>';

				$display_count ++;
			}
		}
	}

	return apply_filters( 'wvs_variable_item', $data, $type, $options, $args, $saved_attribute );
}

// Function override
function wvs_default_variable_item( $type, $options, $args, $saved_attribute = array() ) {

	$product   = $args['product'];
	$attribute = $args['attribute'];
	$assigned  = $args['assigned'];

	$is_archive           = ( isset( $args['is_archive'] ) && $args['is_archive'] );
	$show_archive_tooltip = (bool) woo_variation_swatches()->get_option( 'show_tooltip_on_archive' );

	$linkable_attribute = ( (bool) woo_variation_swatches()->get_option( 'linkable_attribute' ) && ( woo_variation_swatches()->get_option( 'trigger_catalog_mode' ) == 'hover' ) );

	$product_url    = $product->get_permalink();
	$attribute_name = wc_variation_attribute_name( $attribute );

	$data = '';

	if ( isset( $args['fallback_type'] ) && $args['fallback_type'] === 'select' ) {
		//	return '';
	}

	if ( ! empty( $options ) ) {
		if ( $product && taxonomy_exists( $attribute ) ) {
			$terms         = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
			$name          = uniqid( wc_variation_attribute_name( $attribute ) );
			$display_count = 0;
			$total_terms   = count( $terms );
			foreach ( $terms as $term ) {
				if ( in_array( $term->slug, $options ) ) {

					$is_selected = ( sanitize_title( $args['selected'] ) == $term->slug );

					$selected_class = $is_selected ? 'selected' : '';
					$tooltip        = trim( apply_filters( 'wvs_variable_item_tooltip', $term->name, $term, $args ) );

					$screen_reader_html_attr = $is_selected ? ' aria-checked="true"' : ' aria-checked="false"';
					$data_url                = '';
					if ( $linkable_attribute && $is_archive ) {
						$url      = esc_url( add_query_arg( $attribute_name, $term->slug, $product_url ) );
						$data_url = sprintf( ' data-url="%s"', $url );
					}

					if ( $is_archive && ! $show_archive_tooltip ) {
						$tooltip = false;
					}

					$tooltip_html_attr = ! empty( $tooltip ) ? sprintf( ' data-wvstooltip="%s"', esc_attr( $tooltip ) ) : '';

					if ( wp_is_mobile() ) {
						$tooltip_html_attr .= ! empty( $tooltip ) ? ' tabindex="2"' : '';
					}

					$type = isset( $assigned[ $term->slug ] ) ? $assigned[ $term->slug ]['type'] : $type;

					if ( ! isset( $assigned[ $term->slug ] ) || empty( $assigned[ $term->slug ]['image_id'] ) ) {
						$type = 'button';
					}

					// More...
					if ( $is_archive && wvs_archive_swatches_has_more( $display_count ) ) {
						$data .= wvs_archive_swatches_more( $product->get_id(), $total_terms );
						break;
					}


					$data .= sprintf( '<li %1$s class="variable-item %2$s-variable-item %2$s-variable-item-%3$s %4$s" data-title="%5$s" title="%5$s" data-value="%3$s"  role="radio" tabindex="0"><div class="variable-item-contents">', $data_url . $screen_reader_html_attr . $tooltip_html_attr, esc_attr( $type ), esc_attr( $term->slug ), esc_attr( $selected_class ), esc_html( $term->name ) );

					switch ( $type ):

						case 'image':
							$attachment_id = $assigned[ $term->slug ]['image_id'];
							$image_size    = woo_variation_swatches()->get_option( 'attribute_image_size' );
							$image         = wp_get_attachment_image_src( $attachment_id, apply_filters( 'wvs_product_attribute_image_size', $image_size, $attribute, $product ) );

							$data .= sprintf( '<img aria-hidden="true" alt="%s" src="%s" width="%d" height="%d" />', esc_attr( apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $attribute, $product ) ), esc_url( $image[0] ), $image[1], $image[2] );
							// $data .= $image_html;
							break;


						case 'button':
							$data .= sprintf( '<span class="variable-item-span variable-item-span-%s">%s</span>', esc_attr( $type ), esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $attribute, $product ) ) );
							break;

						default:
							$data .= apply_filters( 'wvs_variable_default_item_content', '', $term, $args, $saved_attribute );
							break;
					endswitch;


					if ( (bool) woo_variation_swatches()->get_option( 'show_variation_stock_info' ) ) {
						$data .= '<span class="wvs-stock-left-info" data-wvs-stock-info=""></span>';
					}

					$data .= '</div></li>';
					$display_count ++;
				}
			}
		} else {

			$display_count = 0;
			$total_terms   = count( $options );
			foreach ( $options as $option ) {
				// This handles < 2.4.0 bw compatibility where text attributes were not sanitized.

				$option = esc_html( apply_filters( 'woocommerce_variation_option_name', $option, null, $attribute, $product ) );

				$is_selected             = ( sanitize_title( $option ) == sanitize_title( $args['selected'] ) );
				$selected_class          = $is_selected ? 'selected' : '';
				$screen_reader_html_attr = $is_selected ? ' aria-checked="true"' : ' aria-checked="false"';

				$data_url = '';
				if ( $linkable_attribute && $is_archive ) {
					$url      = esc_url( add_query_arg( $attribute_name, sanitize_title( $option ), $product_url ) );
					$data_url = sprintf( ' data-url="%s"', $url );
				}

				$tooltip = trim( apply_filters( 'wvs_variable_item_tooltip', esc_attr( $option ), $options, $args ) );

				if ( $is_archive && ! $show_archive_tooltip ) {
					$tooltip = false;
				}

				$tooltip_html_attr = ! empty( $tooltip ) ? sprintf( ' data-wvstooltip="%s"', esc_attr( $tooltip ) ) : '';

				if ( wp_is_mobile() ) {
					$tooltip_html_attr .= ! empty( $tooltip ) ? ' tabindex="2"' : '';
				}

				$type = isset( $assigned[ $option ] ) ? $assigned[ $option ]['type'] : $type;

				if ( ! isset( $assigned[ $option ] ) || empty( $assigned[ $option ]['image_id'] ) ) {
					$type = 'button';
				}

				// More...
				if ( $is_archive && wvs_archive_swatches_has_more( $display_count ) ) {
					$data .= wvs_archive_swatches_more( $product->get_id(), $total_terms );
					break;
				}

				$data .= sprintf( '<li %1$s class="variable-item %2$s-variable-item %2$s-variable-item-%3$s %4$s" data-title="%5$s" title="%5$s" data-value="%3$s" role="radio" tabindex="0"><div class="variable-item-contents">', $data_url . $screen_reader_html_attr . $tooltip_html_attr, esc_attr( $type ), esc_attr( $option ), esc_attr( $selected_class ), esc_html( $option ) );

				switch ( $type ):

					case 'image':
						$attachment_id = $assigned[ $option ]['image_id'];
						$image_size    = woo_variation_swatches()->get_option( 'attribute_image_size' );
						$image         = wp_get_attachment_image_src( $attachment_id, apply_filters( 'wvs_product_attribute_image_size', $image_size, $attribute, $product ) );

						$data .= sprintf( '<img aria-hidden="true" alt="%s" src="%s" width="%d" height="%d" />', esc_attr( $option ), esc_url( $image[0] ), esc_attr( $image[1] ), esc_attr( $image[2] ) );
						// $data .= $image_html;
						break;


					case 'button':
						$data .= sprintf( '<span class="variable-item-span variable-item-span-%s">%s</span>', esc_attr( $type ), esc_html( $option ) );
						break;

					default:
						$data .= apply_filters( 'wvs_variable_default_item_content', '', $option, $args, array() );
						break;
				endswitch;

				if ( (bool) woo_variation_swatches()->get_option( 'show_variation_stock_info' ) ) {
					$data .= '<span class="wvs-stock-left-info" data-wvs-stock-info=""></span>';
				}

				$data .= '</div></li>';
				$display_count ++;

			}
		}
	}

	return apply_filters( 'wvs_default_variable_item', $data, $type, $options, $args, array() );
}

function wvs_color_variation_attribute_preview( $term_id, $attribute, $fields ) {

	$key            = $fields[0]['id'];
	$is_dual_key    = $fields[1]['id'];
	$dual_color_key = $fields[2]['id'];

	$value = sanitize_hex_color( get_term_meta( $term_id, $key, true ) );

	$is_dual = (bool) ( get_term_meta( $term_id, $is_dual_key, true ) === 'yes' );

	if ( $is_dual ) {
		$secondary_color = sanitize_hex_color( get_term_meta( $term_id, $dual_color_key, true ) );
		printf( '<div class="wvs-preview wvs-color-preview wvs-dual-color-preview" style="background: linear-gradient(-45deg, %1$s 0%%, %1$s 50%%, %2$s 50%%, %2$s 100%%);"></div>', esc_attr( $secondary_color ), esc_attr( $value ) );
	} else {
		printf( '<div class="wvs-preview wvs-color-preview" style="background-color:%s;"></div>', esc_attr( $value ) );
	}
}

//-------------------------------------------------------------------------------
// WooCommerce Core Function Override
//-------------------------------------------------------------------------------

if ( ! function_exists( 'woocommerce_variable_add_to_cart' ) ):
	function woocommerce_variable_add_to_cart() {
		global $product;
		// Enqueue variation scripts.
		wp_enqueue_script( 'wc-add-to-cart-variation' );

		$product_id   = $product->get_id();
		$attributes   = $product->get_variation_attributes();
		$selected_all = array();

		foreach ( $attributes as $attribute_name => $options ) {
			$selected_key                  = 'attribute_' . sanitize_title( $attribute_name );
			$selected                      = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( wp_unslash( urldecode( $_REQUEST[ $selected_key ] ) ) ) : $product->get_variation_default_attribute( $attribute_name );
			$selected_all[ $selected_key ] = $selected;
		}

		$transient_key  = md5( wp_json_encode( $selected_all ) );
		$transient_name = sprintf( 'wvs_template_%s%s', $product_id, $transient_key );
		$cache          = new Woo_Variation_Swatches_Cache( $transient_name, 'wvs_template' );
		$use_transient  = (bool) woo_variation_swatches()->get_option( 'use_transient' );

		// Clear cache
		if ( isset( $_GET['wvs_clear_transient'] ) ) {
			$cache->delete_transient();
		}

		// Return cache
		if ( $use_transient ) {
			$transient_html = $cache->get_transient( $transient_name );
			if ( ! empty( $transient_html ) ) {
				echo $transient_html . '<!-- from woocommerce_variable_add_to_cart  -->';

				return;
			}
		}

		ob_start();

		// Get Available variations?
		$get_variations = count( $product->get_children() ) <= apply_filters( 'woocommerce_ajax_variation_threshold', 30, $product );

		$available_variations = $get_variations ? array_values( $product->get_available_variations() ) : false;

		$selected_attributes = $product->get_default_attributes();

		// Load the template.
		wc_get_template(
			'single-product/add-to-cart/variable.php', apply_filters(
				'wvs_woocommerce_variable_add_to_cart_template_args', array(
					'available_variations' => $available_variations,
					'attributes'           => $attributes,
					'selected_attributes'  => $selected_attributes,
				)
			)
		);

		$html = ob_get_clean();
		// Set cache
		if ( $use_transient ) {
			$cache->set_transient( $html, DAY_IN_SECONDS );
		}

		echo $html;
	}
endif;

//-------------------------------------------------------------------------------
// WooCommerce Get Attribute Taxonomies
//-------------------------------------------------------------------------------

if ( ! function_exists( 'wvs_pro_get_attribute_taxonomies_option' ) ):
	function wvs_pro_get_attribute_taxonomies_option( $empty = ' - Choose Attribute - ' ) {
		// attribute_name | attribute_id
		$lists = (array) wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' );

		$list = array();
		foreach ( $lists as $name => $label ) {
			$list[ wc_attribute_taxonomy_name( $name ) ] = $label . " ( {$name} )";
		}

		if ( $empty ) {
			$list = array( '' => $empty ) + $list;
		}

		return $list;
	}
endif;

if ( ! function_exists( 'wvs_pro_attribute_taxonomy_type_by_name' ) ):
	function wvs_pro_attribute_taxonomy_type_by_name( $name ) {
		$name       = str_replace( 'pa_', '', wc_sanitize_taxonomy_name( $name ) );
		$taxonomies = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_type', 'attribute_name' );

		return isset( $taxonomies[ $name ] ) ? $taxonomies[ $name ] : false;
	}
endif;





Youez - 2016 - github.com/yon3zu
LinuXploit