WC_GZD_Shortcodes

Adds Germanized Shortcodes.

Defined (1)

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

/includes/class-wc-gzd-shortcodes.php  
  1. class WC_GZD_Shortcodes { 
  2.  
  3. /** 
  4. * Initializes Shortcodes 
  5. */ 
  6. public static function init() { 
  7.  
  8. // Rename the original WooCommerce Shortcode tag so that we can add our custom function to it 
  9. add_filter( 'add_to_cart_shortcode_tag', __CLASS__ . '::replace_add_to_cart_shortcode', 10 ); 
  10.  
  11. // Define shortcodes 
  12. $shortcodes = array( 
  13. 'revocation_form' => __CLASS__ . '::revocation_form',  
  14. 'payment_methods_info' => __CLASS__ . '::payment_methods_info',  
  15. 'ekomi_badge' => __CLASS__ . '::ekomi_badge',  
  16. 'ekomi_widget' => __CLASS__ . '::ekomi_widget',  
  17. 'add_to_cart' => __CLASS__ . '::gzd_add_to_cart',  
  18. 'gzd_feature' => __CLASS__ . '::gzd_feature',  
  19. 'gzd_vat_info' => __CLASS__ . '::gzd_vat_info',  
  20. 'gzd_sale_info' => __CLASS__ . '::gzd_sale_info',  
  21. 'gzd_complaints' => __CLASS__ . '::gzd_complaints',  
  22. ); 
  23.  
  24. foreach ( $shortcodes as $shortcode => $function ) { 
  25. add_shortcode( apply_filters( "gzd_{$shortcode}_shortcode_tag", $shortcode ), $function ); 
  26.  
  27.  
  28. public static function gzd_add_price_suffixes( $price, $product ) { 
  29. global $product; 
  30.  
  31. ob_start(); 
  32. woocommerce_gzd_template_single_legal_info(); 
  33. $legal = ob_get_clean(); 
  34.  
  35. ob_start(); 
  36. woocommerce_gzd_template_single_price_unit(); 
  37. $unit = ob_get_clean(); 
  38.  
  39. return $price . strip_tags( $unit . $legal, '<span><a>' ); 
  40.  
  41. public static function gzd_add_to_cart( $atts ) { 
  42.  
  43. add_filter( 'woocommerce_get_price_html', __CLASS__ . '::gzd_add_price_suffixes', 10, 2 ); 
  44.  
  45. $html = WC_Shortcodes::product_add_to_cart( $atts ); 
  46.  
  47. remove_filter( 'woocommerce_get_price_html', __CLASS__ . '::gzd_add_price_features', 10 ); 
  48.  
  49. return $html; 
  50.  
  51. public static function replace_add_to_cart_shortcode( $shortcode ) { 
  52. return 'add_to_cart_legacy'; 
  53.  
  54. public static function gzd_complaints( $atts ) { 
  55. $texts = array( 
  56. 'dispute' => wc_gzd_get_dispute_resolution_text(),  
  57. ); 
  58.  
  59. foreach( $texts as $key => $text ) { 
  60. $texts[ $key ] = wpautop( str_replace( 'http://ec.europa.eu/consumers/odr/', '<a href="http://ec.europa.eu/consumers/odr/" target="_blank">http://ec.europa.eu/consumers/odr/</a>', $text ) ); 
  61.  
  62. ob_start(); 
  63. wc_get_template( 'global/complaints.php', array( 'dispute_text' => $texts[ 'dispute' ] ) ); 
  64. $return = '<div class="woocommerce woocommerce-gzd woocommerce-gzd-complaints-shortcode">' . ob_get_clean() . '</div>'; 
  65.  
  66. return $return; 
  67.  
  68. /** 
  69. * Returns revocation_form template html 
  70. *  
  71. * @param array $atts  
  72. * @return string revocation form html  
  73. */ 
  74. public static function revocation_form( $atts ) { 
  75. ob_start(); 
  76. wc_get_template( 'forms/revocation-form.php' ); 
  77. $return = '<div class="woocommerce woocommerce-gzd">' . ob_get_clean() . '</div>'; 
  78. return $return; 
  79.  
  80. /** 
  81. * Returns payment methods info html 
  82. *  
  83. * @param array $atts 
  84. * @return string 
  85. */ 
  86. public static function payment_methods_info( $atts ) { 
  87.  
  88. WC_GZD_Payment_Gateways::instance()->manipulate_gateways(); 
  89.  
  90. ob_start(); 
  91. wc_get_template( 'global/payment-methods.php' ); 
  92. $return = '<div class="woocommerce woocommerce-gzd">' . ob_get_clean() . '</div>'; 
  93. return $return; 
  94.  
  95.  
  96. /** 
  97. * Returns eKomi Badge html 
  98. *  
  99. * @param array $atts  
  100. * @return string  
  101. */ 
  102. public static function ekomi_badge( $atts ) { 
  103.  
  104. return WC_germanized()->ekomi->get_badge( $atts ); 
  105.  
  106.  
  107. /** 
  108. * Returns eKomi Widget html 
  109. *  
  110. * @param array $atts  
  111. * @return string  
  112. */ 
  113. public static function ekomi_widget( $atts ) { 
  114.  
  115. return WC_germanized()->ekomi->get_widget( $atts ); 
  116.  
  117.  
  118. /** 
  119. * Returns header feature shortcode 
  120. *  
  121. * @param array $atts  
  122. * @param string $content  
  123. * @return string  
  124. */ 
  125. public static function gzd_feature( $atts, $content = '' ) { 
  126.  
  127. extract( shortcode_atts( array('icon' => ''), $atts ) ); 
  128. return ( !empty( $icon ) ? '<i class="fa fa-' . $icon . '"></i> ' : '' ) . $content; 
  129.  
  130.  
  131. /** 
  132. * Returns VAT info 
  133. *  
  134. * @param array $atts  
  135. * @param string $content  
  136. * @return string  
  137. */ 
  138. public static function gzd_vat_info( $atts, $content = '' ) { 
  139.  
  140. ob_start(); 
  141. wc_get_template( 'footer/vat-info.php' ); 
  142. return ob_get_clean(); 
  143.  
  144.  
  145. /** 
  146. * Returns Sale info 
  147. *  
  148. * @param array $atts  
  149. * @param string $content  
  150. * @return string  
  151. */ 
  152. public static function gzd_sale_info( $atts, $content = '' ) { 
  153.  
  154. ob_start(); 
  155. wc_get_template( 'footer/sale-info.php' ); 
  156. return ob_get_clean(); 
  157.  
  158.