YITH_WCWL_UI

YITH_WCWL_UI class, with methods used to print user interface.

Defined (1)

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

/includes/class.yith-wcwl-ui.php  
  1. class YITH_WCWL_UI { 
  2.  
  3. /** 
  4. * Build the popup message HTML/jQuery. 
  5. * @return string 
  6. * @static 
  7. * @since 1.0.0 
  8. */ 
  9. public static function popup_message() { 
  10. _deprecated_function( 'popup_message', '2.0.0', 'add-to-wishlist-button.php template' ); 
  11. ob_start() ?> 
  12.  
  13. <script type="text/javascript"> 
  14. if( !jQuery( '#yith-wcwl-popup-message' ).length ) { 
  15. jQuery( 'body' ).prepend( 
  16. '<div id="yith-wcwl-popup-message" style="display:none;">' + 
  17. '<div id="yith-wcwl-message"></div>' + 
  18. '</div>' 
  19. ); 
  20. </script> 
  21.  
  22. <?php 
  23. return ob_get_clean(); 
  24.  
  25. /** 
  26. * Build the "Add to Wishlist" HTML 
  27. * @deprecated 
  28. * @param string $url 
  29. * @param string $product_type 
  30. * @param bool $exists 
  31. * @return string 
  32. * @static 
  33. * @since 1.0.0 
  34. */ 
  35. public static function add_to_wishlist_button( $url, $product_type, $exists ) { 
  36. _deprecated_function( 'add_to_wishlist_button', '2.0.0', 'add-to-wishlist-button.php template' ); 
  37.  
  38. global $yith_wcwl, $product; 
  39.  
  40. $label_option = get_option( 'yith_wcwl_add_to_wishlist_text' ); 
  41. $localize_label = function_exists( 'icl_translate' ) ? icl_translate( 'Plugins', 'plugin_yit_wishlist_button', $label_option ) : $label_option; 
  42.  
  43. $label = apply_filters( 'yith_wcwl_button_label', $localize_label ); 
  44. $icon = get_option( 'yith_wcwl_add_to_wishlist_icon' ) != 'none' ? '<i class="fa ' . get_option( 'yith_wcwl_add_to_wishlist_icon' ) . '"></i>' : ''; 
  45.  
  46. $classes = get_option( 'yith_wcwl_use_button' ) == 'yes' ? 'class="add_to_wishlist single_add_to_wishlist button alt"' : 'class="add_to_wishlist"'; 
  47.  
  48. $html = '<div class="yith-wcwl-add-to-wishlist">'; 
  49. $html .= '<div class="yith-wcwl-add-button'; // the class attribute is closed in the next row 
  50.  
  51. $html .= $exists ? ' hide" style="display:none;"' : ' show"'; 
  52.  
  53. $html .= '><a href="' . esc_url( add_query_arg( 'add_to_wishlist', $product->id ) ) . '" data-product-id="' . $product->id . '" data-product-type="' . $product_type . '" ' . $classes . ' >' . $icon . $label . '</a>'; 
  54. $html .= '<img src="' . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . '" class="ajax-loading" alt="loading" width="16" height="16" style="visibility:hidden" />'; 
  55. $html .= '</div>'; 
  56.  
  57. $html .= '<div class="yith-wcwl-wishlistaddedbrowse hide" style="display:none;"><span class="feedback">' . __( 'Product added!', 'yith-woocommerce-wishlist' ) . '</span> <a href="' . esc_url( $url ) . '">' . apply_filters( 'yith-wcwl-browse-wishlist-label', __( 'Browse Wishlist', 'yith-woocommerce-wishlist' ) ) . '</a></div>'; 
  58. $html .= '<div class="yith-wcwl-wishlistexistsbrowse ' . ( $exists ? 'show' : 'hide' ) . '" style="display:' . ( $exists ? 'block' : 'none' ) . '"><span class="feedback">' . __( 'The product is already in the wishlist!', 'yith-woocommerce-wishlist' ) . '</span> <a href="' . esc_url( $url ) . '">' . apply_filters( 'yith-wcwl-browse-wishlist-label', __( 'Browse Wishlist', 'yith-woocommerce-wishlist' ) ) . '</a></div>'; 
  59. $html .= '<div style="clear:both"></div><div class="yith-wcwl-wishlistaddresponse"></div>'; 
  60.  
  61. $html .= '</div>'; 
  62. $html .= '<div class="clear"></div>'; 
  63.  
  64. return $html; 
  65.  
  66. /** 
  67. * Build the "Add to cart" HTML. 
  68. * @deprecated 
  69. * @param string $url 
  70. * @param string $stock_status 
  71. * @param string $type 
  72. * @return string 
  73. * @static 
  74. * @since 1.0.0 
  75. */ 
  76. public static function add_to_cart_button( $product_id, $stock_status ) { 
  77. _deprecated_function( 'add_to_cart_button', '2.0.0', 'wc_get_template( "loop/add-to-cart.php" )' ); 
  78.  
  79. global $yith_wcwl, $product; 
  80.  
  81. if ( function_exists( 'get_product' ) ) 
  82. $product = get_product( $product_id ); 
  83. else 
  84. $product = new WC_Product( $product_id ); 
  85.  
  86. $url = $product->product_type == 'external' ? $yith_wcwl->get_affiliate_product_url( $product_id ) : $yith_wcwl->get_addtocart_url( $product_id ); 
  87.  
  88. $label_option = get_option( 'yith_wcwl_add_to_cart_text' ); 
  89. $localize_label = function_exists( 'icl_translate' ) ? icl_translate( 'Plugins', 'plugin_yit_wishlist_button', $label_option ) : $label_option; 
  90.  
  91. $label = $product->product_type == 'variable' ? apply_filters( 'variable_add_to_cart_text', __('Select options', 'yith-woocommerce-wishlist') ) : apply_filters( 'yith_wcwl_add_to_cart_label', $localize_label ); 
  92. $icon = get_option( 'yith_wcwl_use_button' ) == 'yes' && get_option( 'yith_wcwl_add_to_cart_icon' ) != 'none' ? '<i class="fa ' . get_option( 'yith_wcwl_add_to_cart_icon' ) . '"></i>' : ''; 
  93.  
  94. $cartlink = ''; 
  95. $redirect_to_cart = get_option( 'yith_wcwl_redirect_cart' ) == 'yes' && $product->product_type != 'variable' ? 'true' : 'false'; 
  96. $style = ''; //indicates the style (background-color and font color) 
  97.  
  98. if( get_option( 'yith_wcwl_use_button' ) == 'yes' ) { 
  99. if( $product->product_type == 'external' ) { 
  100. $cartlink .= '<a target="_blank" class="add_to_cart button alt" href="' . $url . '"'; 
  101. } else { 
  102. $cartlink .= '<a class="add_to_cart add_to_cart_from_wishlist button alt" href="' . $url . '" data-stock-status="' . $stock_status . '" data-redirect-to-cart="' . $redirect_to_cart . '"'; 
  103.  
  104. $cartlink .= $style . '>' . $icon . $label . '</a>'; 
  105. } else { 
  106. if( $product->product_type == 'external' ) { 
  107. $cartlink .= '<a target="_blank" class="add_to_cart button alt" href="' . $url . '">' . $icon . $label . '</a>'; 
  108. } else { 
  109. $cartlink .= '<a class="add_to_cart add_to_cart_from_wishlist button alt" href="' . $url . '" data-stock-status="' . $stock_status . '" data-redirect-to-cart="' . $redirect_to_cart . '">' . $icon . $label . '</a>'; 
  110.  
  111. return $cartlink; 
  112.  
  113. /** 
  114. * Build share HTML. 
  115. * @deprecated 
  116. * @param string $url 
  117. * @return string $string 
  118. * @static 
  119. * @since 1.0.0 
  120. */ 
  121. public static function get_share_links( $url ) { 
  122. _deprecated_function( 'get_share_links', '2.0.0', 'share.php template' ); 
  123.  
  124. $normal_url = $url; 
  125. $url = urlencode( $url ); 
  126. $title = apply_filters( 'plugin_text', urlencode( get_option( 'yith_wcwl_socials_title' ) ) ); 
  127. $twitter_summary = str_replace( '%wishlist_url%', '', get_option( 'yith_wcwl_socials_text' ) ); 
  128. $summary = urlencode( str_replace( '%wishlist_url%', $normal_url, get_option( 'yith_wcwl_socials_text' ) ) ); 
  129. $imageurl = urlencode( get_option( 'yith_wcwl_socials_image_url' ) ); 
  130.  
  131. $html = '<div class="yith-wcwl-share">'; 
  132. $html .= apply_filters( 'yith_wcwl_socials_share_title', '<span>' . __( 'Share on:', 'yith-woocommerce-wishlist' ) . '</span>' ); 
  133. $html .= '<ul>'; 
  134.  
  135. if( get_option( 'yith_wcwl_share_fb' ) == 'yes' ) 
  136. { $html .= '<li style="list-style-type: none; display: inline-block;"><a target="_blank" class="facebook" href="https://www.facebook.com/sharer.php?s=100&p[title]=' . $title . '&p[url]=' . $url . '&p[summary]=' . $summary . '&p[images][0]=' . $imageurl . '" title="' . __( 'Facebook', 'yith-woocommerce-wishlist' ) . '"></a></li>'; } 
  137.  
  138. if( get_option( 'yith_wcwl_share_twitter' ) == 'yes' ) 
  139. { $html .= '<li style="list-style-type: none; display: inline-block;"><a target="_blank" class="twitter" href="https://twitter.com/share?url=' . $url . '&text=' . $twitter_summary . '" title="' . __( 'Twitter', 'yith-woocommerce-wishlist' ) . '"></a></li>'; } 
  140.  
  141. if( get_option( 'yith_wcwl_share_pinterest' ) == 'yes' ) 
  142. { $html .= '<li style="list-style-type: none; display: inline-block;"><a target="_blank" class="pinterest" href="http://pinterest.com/pin/create/button/?url=' . $url . '&description=' . $summary . '&media=' . $imageurl . '" onclick="window.open(this.href); return false;"></a></li>'; } 
  143.  
  144. if( get_option( 'yith_wcwl_share_googleplus' ) == 'yes' ) 
  145. { $html .= '<li style="list-style-type: none; display: inline-block;"><a target="_blank" class="googleplus" href="https://plus.google.com/share?url=' . $url . '&title=' . $title . '" title="' . $title . '" onclick=\'javascript:window.open(this.href, "", "menubar=no, toolbar=no, resizable=yes, scrollbars=yes, height=600, width=600");return false;\'></a></li>'; } 
  146.  
  147. if( get_option( 'yith_wcwl_share_email' ) == 'yes' ) 
  148. { $html .= '<li style="list-style-type: none; display: inline-block;"><a class="email" href="mailto:?subject=I wanted you to see this site&body= ' . $url . '&title=' . __('email', 'yith-woocommerce-wishlist') . '" title="' . $title . '" ></a></li>'; } 
  149.  
  150. $html .= '</ul>'; 
  151. $html .= '</div>'; 
  152.  
  153. return $html; 
  154.  
  155. /** 
  156. * Adds classes to add-to-cart button 
  157. * @param $button_html string 
  158. * @param $product \WC_Product 
  159. * @return string 
  160. * @static 
  161. * @since 2.0.0 
  162. */ 
  163. public static function alter_add_to_cart_button( $button_html, $product ) { 
  164. // retrieve options 
  165. $label_option = get_option( 'yith_wcwl_add_to_cart_text' ); 
  166. $label = $product->is_type( 'variable' ) ? apply_filters( 'variable_add_to_cart_text', __('Select options', 'yith-woocommerce-wishlist') ) : apply_filters( 'yith_wcwl_add_to_cart_label', $label_option ); 
  167. $icon = ''; 
  168.  
  169. if( get_option( 'yith_wcwl_frontend_css' ) != 'yes' && get_option( 'yith_wcwl_use_button' ) == 'yes' && get_option( 'yith_wcwl_add_to_cart_icon' ) != 'none' ) { 
  170. $icon = '<i class="fa ' . get_option( 'yith_wcwl_add_to_cart_icon' ) . '"></i>'; 
  171.  
  172. // customize 
  173. $match = array(); 
  174. preg_match( '/<a.*class="([^"]*).*>.*<\/a>/', $button_html, $match ); 
  175.  
  176. if( ! empty( $match ) && isset( $match[1] ) ) { 
  177. $button_html = str_replace( $match[1], $match[1] . ' add_to_cart button alt', $button_html ); 
  178.  
  179. preg_match( '/<a .*?>(.*)<\/a>/', $button_html, $match ); 
  180.  
  181. if( ! empty( $match ) && isset( $match[1] ) ) { 
  182. $button_html = str_replace( $match[1], $icon . ' ' . $label, $button_html ); 
  183.  
  184. return $button_html;