WC_Predictive_Search_Functions

WooCommerce Predictive Search Functions.

Defined (1)

The class is defined in the following location(s).

/classes/class-wc-predictive-search-functions.php  
  1. class WC_Predictive_Search_Functions 
  2.  
  3. public static function symbol_entities() { 
  4. $symbol_entities = array( 
  5. "_" => "_",  
  6. "(" => "(",  
  7. ")" => ")",  
  8. "{" => "{",  
  9. "}" => "}",  
  10. "<" => "<",  
  11. ">" => ">",  
  12. "" => "«",  
  13. "" => "»",  
  14. "*" => "‘",  
  15. "*" => "’",  
  16. "*" => "“",  
  17. "*" => "”",  
  18. "*" => "‐",  
  19. "-" => "-",  
  20. "*" => "–",  
  21. "*" => "—",  
  22. "*" => "←",  
  23. "*" => "→",  
  24. "*" => "↑",  
  25. "*" => "↓",  
  26. "" => "©",  
  27. "" => "®",  
  28. "*" => "™",  
  29. "*" => "€",  
  30. "" => "£",  
  31. "" => "¥",  
  32. "" => "¢",  
  33. "" => "§",  
  34. "*" => "∑",  
  35. "" => "µ",  
  36. "" => "¶",  
  37. "" => "¿",  
  38. "" => "¡",  
  39.  
  40. ); 
  41.  
  42. return apply_filters( 'wc_ps_symbol_entities', $symbol_entities ); 
  43.  
  44. public static function get_argument_vars() { 
  45. $argument_vars = array( 'keyword' , 'search-in', 'cat-in', 'search-other' ); 
  46. return $argument_vars; 
  47.  
  48. public static function special_characters_list() { 
  49. $special_characters = array(); 
  50. foreach ( self::symbol_entities() as $symbol => $entity ) { 
  51. $special_characters[$symbol] = $symbol; 
  52.  
  53. return apply_filters( 'wc_ps_special_characters', $special_characters ); 
  54.  
  55. public static function is_enable_special_characters () { 
  56. $enable_special_characters = true; 
  57.  
  58. $woocommerce_search_remove_special_character = get_option( 'woocommerce_search_remove_special_character', 'no' ); 
  59. if ( 'no' == $woocommerce_search_remove_special_character ) { 
  60. $enable_special_characters = false; 
  61.  
  62. $woocommerce_search_special_characters = get_option( 'woocommerce_search_special_characters', array() ); 
  63. if ( !is_array( $woocommerce_search_special_characters ) || count( $woocommerce_search_special_characters ) < 1 ) { 
  64. $enable_special_characters = false; 
  65.  
  66. return $enable_special_characters; 
  67.  
  68. public static function replace_mysql_command( $field_name, $special_symbol, $replace_special_character = 'ignore' ) { 
  69. if ( 'ignore' == $replace_special_character ) { 
  70. $field_name = 'REPLACE( '.$field_name.', " '.$special_symbol.' ", "")'; 
  71. $field_name = 'REPLACE( '.$field_name.', " '.$special_symbol.'", "")'; 
  72. $field_name = 'REPLACE( '.$field_name.', "'.$special_symbol.' ", "")'; 
  73. $field_name = 'REPLACE( '.$field_name.', "'.$special_symbol.'", "")'; 
  74. } else { 
  75. $field_name = 'REPLACE( '.$field_name.', " '.$special_symbol.' ", " ")'; 
  76. $field_name = 'REPLACE( '.$field_name.', " '.$special_symbol.'", " ")'; 
  77. $field_name = 'REPLACE( '.$field_name.', "'.$special_symbol.' ", " ")'; 
  78. $field_name = 'REPLACE( '.$field_name.', "'.$special_symbol.'", " ")'; 
  79.  
  80. return $field_name; 
  81.  
  82. public static function remove_special_characters_in_mysql( $field_name, $search_keyword = '' ) { 
  83. global $wpdb; 
  84.  
  85. $sql_after = ''; 
  86.  
  87. if ( '' == trim( $field_name ) || '' == trim( $search_keyword ) ) { 
  88. return $sql_after; 
  89.  
  90. global $predictive_search_mode; 
  91.  
  92. // This is original query 
  93. if ( 'broad' != $predictive_search_mode ) { 
  94. $sql_after = $wpdb->prepare( $field_name . " LIKE %s OR " . $field_name . " LIKE %s ", $search_keyword.'%', '% '.$search_keyword.'%' ); 
  95. } else { 
  96. $sql_after = $wpdb->prepare( $field_name . " LIKE %s ", '%'.$search_keyword.'%' ); 
  97.  
  98. if ( ! self::is_enable_special_characters() ) { 
  99. return $sql_after; 
  100.  
  101. $replace_special_character = get_option( 'woocommerce_search_replace_special_character', 'remove' ); 
  102. $woocommerce_search_special_characters = get_option( 'woocommerce_search_special_characters', array() ); 
  103.  
  104. foreach ( $woocommerce_search_special_characters as $special_symbol ) { 
  105.  
  106. if ( 'both' == $replace_special_character ) { 
  107. if ( 'broad' != $predictive_search_mode ) { 
  108. $sql_after .= " OR ". $wpdb->prepare( self::replace_mysql_command( $field_name, $special_symbol, 'ignore' ) . " LIKE %s OR " . self::replace_mysql_command( $field_name, $special_symbol, 'ignore' ) . " LIKE %s ", $search_keyword.'%', '% '.$search_keyword.'%' ); 
  109. $sql_after .= " OR ". $wpdb->prepare( self::replace_mysql_command( $field_name, $special_symbol, 'remove' ) . " LIKE %s OR " . self::replace_mysql_command( $field_name, $special_symbol, 'remove' ) . " LIKE %s ", $search_keyword.'%', '% '.$search_keyword.'%' ); 
  110. } else { 
  111. $sql_after .= " OR ". $wpdb->prepare( self::replace_mysql_command( $field_name, $special_symbol, 'ignore' ) . " LIKE %s ", '%'.$search_keyword.'%' ); 
  112. $sql_after .= " OR ". $wpdb->prepare( self::replace_mysql_command( $field_name, $special_symbol, 'remove' ) . " LIKE %s ", '%'.$search_keyword.'%' ); 
  113. } else { 
  114. if ( 'broad' != $predictive_search_mode ) { 
  115. $sql_after .= " OR ". $wpdb->prepare( self::replace_mysql_command( $field_name, $special_symbol, $replace_special_character ) . " LIKE %s OR " . self::replace_mysql_command( $field_name, $special_symbol, $replace_special_character ) . " LIKE %s ", $search_keyword.'%', '% '.$search_keyword.'%' ); 
  116. } else { 
  117. $sql_after .= " OR ". $wpdb->prepare( self::replace_mysql_command( $field_name, $special_symbol, $replace_special_character ) . " LIKE %s ", '%'.$search_keyword.'%' ); 
  118.  
  119.  
  120. return $sql_after; 
  121.  
  122. public static function remove_s_letter_at_end_word( $search_keyword ) { 
  123. $search_keyword_new = ''; 
  124. $search_keyword_new_a = array(); 
  125. $search_keyword_split = explode( " ", trim( $search_keyword ) ); 
  126. if ( is_array( $search_keyword_split ) && count( $search_keyword_split ) > 0 ) { 
  127. foreach ( $search_keyword_split as $search_keyword_element ) { 
  128. if ( strlen( $search_keyword_element ) > 2 ) { 
  129. $search_keyword_new_a[] = rtrim( $search_keyword_element, 's' ); 
  130. } else { 
  131. $search_keyword_new_a[] = $search_keyword_element; 
  132. $search_keyword_new = implode(" ", $search_keyword_new_a); 
  133.  
  134. if ( '' != $search_keyword && $search_keyword_new != $search_keyword ) { 
  135. return $search_keyword_new; 
  136. } else { 
  137. return false; 
  138.  
  139. public static function woops_limit_words($str='', $len=100, $more) { 
  140. if (trim($len) == '' || $len < 0) $len = 100; 
  141. if ( $str=="" || $str==NULL ) return $str; 
  142. if ( is_array($str) ) return $str; 
  143. $str = trim($str); 
  144. $str = strip_tags(str_replace("\r\n", "", $str)); 
  145. if ( strlen($str) <= $len ) return $str; 
  146. $str = substr($str, 0, $len); 
  147. if ( $str != "" ) { 
  148. if ( !substr_count($str, " ") ) { 
  149. if ( $more ) $str .= " ..."; 
  150. return $str; 
  151. while( strlen($str) && ($str[strlen($str)-1] != " ") ) { 
  152. $str = substr($str, 0, -1); 
  153. $str = substr($str, 0, -1); 
  154. if ( $more ) $str .= " ..."; 
  155. return $str; 
  156.  
  157. public static function create_page( $slug, $option, $page_title = '', $page_content = '', $post_parent = 0 ) { 
  158. global $wpdb; 
  159.  
  160. $option_value = get_option($option); 
  161.  
  162. if ( $option_value > 0 && get_post( $option_value ) ) 
  163. return $option_value; 
  164.  
  165. $page_id = $wpdb->get_var( "SELECT ID FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%$page_content%' AND `post_type` = 'page' AND post_status = 'publish' ORDER BY ID ASC LIMIT 1" ); 
  166.  
  167. if ( $page_id != NULL ) : 
  168. if ( ! $option_value ) 
  169. update_option( $option, $page_id ); 
  170. return $page_id; 
  171. endif; 
  172.  
  173. $page_data = array( 
  174. 'post_status' => 'publish',  
  175. 'post_type' => 'page',  
  176. 'post_author' => 1,  
  177. 'post_name' => $slug,  
  178. 'post_title' => $page_title,  
  179. 'post_content' => $page_content,  
  180. 'post_parent' => $post_parent,  
  181. 'comment_status' => 'closed' 
  182. ); 
  183. $page_id = wp_insert_post( $page_data ); 
  184.  
  185. if ( class_exists('SitePress') ) { 
  186. global $sitepress; 
  187. $source_lang_code = $sitepress->get_default_language(); 
  188. $trid = $sitepress->get_element_trid( $page_id, 'post_page' ); 
  189. if ( ! $trid ) { 
  190. $wpdb->query( "UPDATE ".$wpdb->prefix . "icl_translations SET trid=".$page_id." WHERE element_id=".$page_id." AND language_code='".$source_lang_code."' AND element_type='post_page' " ); 
  191.  
  192. update_option( $option, $page_id ); 
  193.  
  194. return $page_id; 
  195.  
  196. public static function create_page_wpml( $trid, $lang_code, $source_lang_code, $slug, $page_title = '', $page_content = '' ) { 
  197. global $wpdb; 
  198.  
  199. $element_id = $wpdb->get_var( "SELECT ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->prefix . "icl_translations AS ic ON p.ID = ic.element_id WHERE p.post_content LIKE '%$page_content%' AND p.post_type = 'page' AND p.post_status = 'publish' AND ic.trid=".$trid." AND ic.language_code = '".$lang_code."' AND ic.element_type = 'post_page' ORDER BY p.ID ASC LIMIT 1" ); 
  200.  
  201. if ( $element_id != NULL ) : 
  202. return $element_id; 
  203. endif; 
  204.  
  205. $page_data = array( 
  206. 'post_date' => gmdate( 'Y-m-d H:i:s' ),  
  207. 'post_modified' => gmdate( 'Y-m-d H:i:s' ),  
  208. 'post_status' => 'publish',  
  209. 'post_type' => 'page',  
  210. 'post_author' => 1,  
  211. 'post_name' => $slug,  
  212. 'post_title' => $page_title,  
  213. 'post_content' => $page_content,  
  214. 'comment_status' => 'closed' 
  215. ); 
  216. $wpdb->insert( $wpdb->posts , $page_data); 
  217. $element_id = $wpdb->insert_id; 
  218.  
  219. //$element_id = wp_insert_post( $page_data ); 
  220.  
  221. $wpdb->insert( $wpdb->prefix . "icl_translations", array( 
  222. 'element_type' => 'post_page',  
  223. 'element_id' => $element_id,  
  224. 'trid' => $trid,  
  225. 'language_code' => $lang_code,  
  226. 'source_language_code' => $source_lang_code,  
  227. ) ); 
  228.  
  229. return $element_id; 
  230.  
  231. public static function auto_create_page_for_wpml( $original_id, $slug, $page_title = '', $page_content = '' ) { 
  232. if ( class_exists('SitePress') ) { 
  233. global $sitepress; 
  234. $active_languages = $sitepress->get_active_languages(); 
  235. if ( is_array($active_languages) && count($active_languages) > 0 ) { 
  236. $source_lang_code = $sitepress->get_default_language(); 
  237. $trid = $sitepress->get_element_trid( $original_id, 'post_page' ); 
  238. foreach ( $active_languages as $language ) { 
  239. if ( $language['code'] == $source_lang_code ) continue; 
  240. WC_Predictive_Search_Functions::create_page_wpml( $trid, $language['code'], $source_lang_code, $slug.'-'.$language['code'], $page_title.' '.$language['display_name'], $page_content ); 
  241.  
  242. public static function get_page_id_from_option( $shortcode, $option ) { 
  243. global $wpdb; 
  244. global $wp_version; 
  245. $page_id = get_option($option); 
  246.  
  247. if ( version_compare( $wp_version, '4.0', '<' ) ) { 
  248. $shortcode = esc_sql( like_escape( $shortcode ) ); 
  249. } else { 
  250. $shortcode = esc_sql( $wpdb->esc_like( $shortcode ) ); 
  251.  
  252. $page_data = null; 
  253. if ( $page_id ) { 
  254. $page_data = $wpdb->get_row( "SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE '%[{$shortcode}]%' AND ID = '".$page_id."' AND post_type = 'page' LIMIT 1" ); 
  255. if ( $page_data == null ) { 
  256. $page_data = $wpdb->get_row( "SELECT ID FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%[{$shortcode}]%' AND `post_type` = 'page' ORDER BY post_date DESC LIMIT 1" ); 
  257.  
  258. $page_id = $page_data->ID; 
  259.  
  260. return $page_id; 
  261.  
  262. public static function get_page_id_from_shortcode( $shortcode, $option ) { 
  263. global $wpdb; 
  264.  
  265. $page_id = self::get_page_id_from_option( $shortcode, $option ); 
  266.  
  267. // For WPML 
  268. if ( class_exists('SitePress') ) { 
  269. global $sitepress; 
  270. $translation_page_data = null; 
  271. $trid = $sitepress->get_element_trid( $page_id, 'post_page' ); 
  272. if ( $trid ) { 
  273. $translation_page_data = $wpdb->get_row( $wpdb->prepare( "SELECT element_id FROM " . $wpdb->prefix . "icl_translations WHERE trid = %d AND element_type='post_page' AND language_code = %s LIMIT 1", $trid , $sitepress->get_current_language() ) ); 
  274. if ( $translation_page_data != null ) 
  275. $page_id = $translation_page_data->element_id; 
  276.  
  277. return $page_id; 
  278.  
  279. public static function add_query_vars( $aVars ) { 
  280. $argument_vars = self::get_argument_vars(); 
  281. foreach ( $argument_vars as $avar ) { 
  282. $aVars[] = $avar; 
  283.  
  284. return $aVars; 
  285.  
  286. public static function add_page_rewrite_rules( $aRules, $page_id ) { 
  287. $search_page = get_page( $page_id ); 
  288.  
  289. if ( ! empty( $search_page ) ) { 
  290.  
  291. $search_page_slug = $search_page->post_name; 
  292. $argument_vars = self::get_argument_vars(); 
  293.  
  294. $rewrite_rule = ''; 
  295. $original_url = ''; 
  296. $number_matches = 0; 
  297. foreach ( $argument_vars as $avar ) { 
  298. $number_matches++; 
  299. $rewrite_rule .= $avar.'/([^/]*)/'; 
  300. $original_url .= '&'.$avar.'=$matches['.$number_matches.']'; 
  301.  
  302. $aNewRules = array($search_page_slug.'/'.$rewrite_rule.'?$' => 'index.php?pagename='.$search_page_slug.$original_url); 
  303. $aRules = $aNewRules + $aRules; 
  304.  
  305.  
  306. return $aRules; 
  307.  
  308. public static function add_rewrite_rules( $aRules ) { 
  309. global $wpdb; 
  310. global $woocommerce_search_page_id; 
  311.  
  312. $shortcode = 'woocommerce_search'; 
  313. $option_name = 'woocommerce_search_page_id'; 
  314.  
  315. $page_id = $woocommerce_search_page_id; 
  316. if ( empty( $page_id ) ) { 
  317. $page_id = self::get_page_id_from_option( $shortcode, $option_name ); 
  318.  
  319. $aRules = self::add_page_rewrite_rules( $aRules, $page_id ); 
  320.  
  321. // For WPML 
  322. if ( class_exists('SitePress') ) { 
  323. global $sitepress; 
  324. $translation_page_data = null; 
  325. $trid = $sitepress->get_element_trid( $page_id, 'post_page' ); 
  326. if ( $trid ) { 
  327. $translation_page_data = $wpdb->get_results( $wpdb->prepare( "SELECT element_id FROM " . $wpdb->prefix . "icl_translations WHERE trid = %d AND element_type='post_page' AND element_id != %d", $trid , $page_id ) ); 
  328. if ( is_array( $translation_page_data ) && count( $translation_page_data ) > 0 ) { 
  329. foreach( $translation_page_data as $translation_page ) { 
  330. $aRules = self::add_page_rewrite_rules( $aRules, $translation_page->element_id ); 
  331.  
  332. return $aRules; 
  333.  
  334. public static function strip_shortcodes ($content='') { 
  335. $content = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $content); 
  336.  
  337. return $content; 
  338.  
  339. /** 
  340. * Get product price 
  341. */ 
  342. public static function get_product_price( $product_id ) { 
  343. $product_price_output = ''; 
  344. $current_db_version = get_option( 'woocommerce_db_version', null ); 
  345. if ( version_compare( $current_db_version, '2.0', '<' ) && null !== $current_db_version ) { 
  346. $current_product = new WC_Product($product_id); 
  347. } elseif ( version_compare( WC()->version, '2.2.0', '<' ) ) { 
  348. $current_product = get_product( $product_id ); 
  349. } else { 
  350. $current_product = wc_get_product( $product_id ); 
  351.  
  352. $product_price_output = $current_product->get_price_html(); 
  353.  
  354. return $product_price_output; 
  355.  
  356. /** 
  357. * Get product add to cart 
  358. */ 
  359. public static function get_product_addtocart( $product_id ) { 
  360. $product_addtocart_output = ''; 
  361. global $product; 
  362. global $post; 
  363. $current_db_version = get_option( 'woocommerce_db_version', null ); 
  364. if ( version_compare( $current_db_version, '2.0', '<' ) && null !== $current_db_version ) { 
  365. $current_product = new WC_Product($product_id); 
  366. } elseif ( version_compare( WC()->version, '2.2.0', '<' ) ) { 
  367. $current_product = get_product( $product_id ); 
  368. } else { 
  369. $current_product = wc_get_product( $product_id ); 
  370. $product = $current_product; 
  371. $post = get_post( $product_id ); 
  372. ob_start(); 
  373. if (function_exists('woocommerce_template_loop_add_to_cart') ) { 
  374. add_filter( 'woocommerce_product_add_to_cart_url', array( 'WC_Predictive_Search_Functions', 'change_add_to_cart_url' ), 10, 2 ); 
  375. woocommerce_template_loop_add_to_cart(); 
  376. $product_addtocart_output = ob_get_clean(); 
  377.  
  378. return $product_addtocart_output; 
  379.  
  380. /** 
  381. * Get product add to cart 
  382. */ 
  383. public static function get_terms_object( $object_id, $taxonomy = 'product_cat' ) { 
  384. $terms_list = array(); 
  385.  
  386. $terms = get_the_terms( $object_id, $taxonomy ); 
  387.  
  388. if ( $terms && ! is_wp_error( $terms ) ) { 
  389. foreach ( $terms as $terms ) { 
  390. $terms_list[] = array( 
  391. 'name' => $terms->name,  
  392. 'url' => get_term_link($terms->slug, $taxonomy ) 
  393. ); 
  394.  
  395. return $terms_list; 
  396.  
  397. /** 
  398. * Get product thumbnail url 
  399. */ 
  400. public static function get_product_thumbnail_url( $post_id, $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) { 
  401. global $woocommerce; 
  402. $woocommerce_db_version = get_option( 'woocommerce_db_version', null ); 
  403. $shop_catalog = ( ( version_compare( $woocommerce_db_version, '2.1', '<' ) ) ? $woocommerce->get_image_size( 'shop_catalog' ) : wc_get_image_size( 'shop_catalog' ) ); 
  404. if ( is_array( $shop_catalog ) && isset( $shop_catalog['width'] ) && $placeholder_width == 0 ) { 
  405. $placeholder_width = $shop_catalog['width']; 
  406. if ( is_array( $shop_catalog ) && isset( $shop_catalog['height'] ) && $placeholder_height == 0 ) { 
  407. $placeholder_height = $shop_catalog['height']; 
  408.  
  409. $mediumSRC = ''; 
  410.  
  411. // Return Feature Image URL 
  412. if ( has_post_thumbnail( $post_id ) ) { 
  413. $thumbid = get_post_thumbnail_id( $post_id ); 
  414. $attachmentArray = wp_get_attachment_image_src( $thumbid, $size, false ); 
  415. if ( $attachmentArray ) { 
  416. $mediumSRC = $attachmentArray[0]; 
  417. if ( trim( $mediumSRC != '' ) ) { 
  418. return $mediumSRC; 
  419.  
  420. // Return First Image URL in gallery of this product 
  421. if ( trim( $mediumSRC == '' ) ) { 
  422. $args = array( 'post_parent' => $post_id , 'numberposts' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'ID', 'post_status' => null ); 
  423. $attachments = get_posts( $args ); 
  424. if ( $attachments ) { 
  425. foreach ( $attachments as $attachment ) { 
  426. $attachmentArray = wp_get_attachment_image_src( $attachment->ID, $size, false ); 
  427. if ( $attachmentArray ) { 
  428. $mediumSRC = $attachmentArray[0]; 
  429. if ( trim( $mediumSRC != '' ) ) { 
  430. return $mediumSRC; 
  431.  
  432. // Ger Image URL of parent product 
  433. if ( trim( $mediumSRC == '' ) ) { 
  434. // Load the product 
  435. $product = get_post( $post_id ); 
  436.  
  437. // Get ID of parent product if one exists 
  438. if ( !empty( $product->post_parent ) ) 
  439. $post_id = $product->post_parent; 
  440.  
  441. if ( has_post_thumbnail( $post_id ) ) { 
  442. $thumbid = get_post_thumbnail_id( $post_id ); 
  443. $attachmentArray = wp_get_attachment_image_src( $thumbid, $size, false ); 
  444. if ( $attachmentArray ) { 
  445. $mediumSRC = $attachmentArray[0]; 
  446. if ( trim( $mediumSRC != '' ) ) { 
  447. return $mediumSRC; 
  448.  
  449. if ( trim( $mediumSRC == '' ) ) { 
  450. $args = array( 'post_parent' => $post_id , 'numberposts' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'ID', 'post_status' => null ); 
  451. $attachments = get_posts( $args ); 
  452. if ( $attachments ) { 
  453. foreach ( $attachments as $attachment ) { 
  454. $attachmentArray = wp_get_attachment_image_src( $attachment->ID, $size, false ); 
  455. if ( $attachmentArray ) { 
  456. $mediumSRC = $attachmentArray[0]; 
  457. if ( trim( $mediumSRC != '' ) ) { 
  458. return $mediumSRC; 
  459.  
  460. // Use place holder image of Woo 
  461. if ( trim( $mediumSRC == '' ) ) { 
  462. $mediumSRC = ( ( version_compare( $woocommerce_db_version, '2.1', '<' ) && null !== $woocommerce_db_version ) ? woocommerce_placeholder_img_src() : wc_placeholder_img_src() ); 
  463.  
  464. return $mediumSRC; 
  465.  
  466. public static function change_add_to_cart_url( $url, $product ) { 
  467. if ( 'simple' == $product->product_type ) { 
  468. $url = $product->is_purchasable() && $product->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( 'add-to-cart', $product->id, get_permalink( $product->id ) ) ) : get_permalink( $product->id ); 
  469. } elseif ( 'variation' == $product->product_type ) { 
  470. $variation_data = array_map( 'urlencode', $product->variation_data ); 
  471. $url = $product->is_purchasable() && $product->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( array_merge( array( 'variation_id' => $product->variation_id, 'add-to-cart' => $product->id ), $variation_data ), get_permalink( $product->id ) ) ) : get_permalink( $product->id ); 
  472.  
  473. return $url;