WooCommerce_Germanized

The WooCommerce Germanized WooCommerce Germanized class.

Defined (1)

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

/woocommerce-germanized.php  
  1. final class WooCommerce_Germanized { 
  2.  
  3. /** 
  4. * Current WooCommerce Germanized Version 
  5. * @var string 
  6. */ 
  7. public $version = '1.8.9'; 
  8.  
  9. /** 
  10. * Single instance of WooCommerce Germanized Main Class 
  11. * @var object 
  12. */ 
  13. protected static $_instance = null; 
  14.  
  15. /** 
  16. * Instance of WC_GZD_Units 
  17. * @var object 
  18. */ 
  19. public $units = null; 
  20.  
  21. public $price_labels = null; 
  22.  
  23. /** 
  24. * WC_GZD_Trusted_Shops instance 
  25. * @var object 
  26. */ 
  27. public $trusted_shops = null; 
  28.  
  29. /** 
  30. * WC_GZD_Ekomi instance 
  31. * @var object 
  32. */ 
  33. public $ekomi = null; 
  34.  
  35. public $emails = null; 
  36.  
  37. public $compatibilities = array(); 
  38.  
  39. /** 
  40. * Main WooCommerceGermanized Instance 
  41. * Ensures that only one instance of WooCommerceGermanized is loaded or can be loaded. 
  42. * @static 
  43. * @see WC_germanized() 
  44. * @return WooCommerceGermanized - Main instance 
  45. */ 
  46. public static function instance() { 
  47. if ( is_null( self::$_instance ) ) { 
  48. self::$_instance = new self(); 
  49. return self::$_instance; 
  50.  
  51. /** 
  52. * Cloning is forbidden. 
  53. * @since 1.0 
  54. */ 
  55. public function __clone() { 
  56. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-germanized' ), '1.0' ); 
  57.  
  58. /** 
  59. * Unserializing instances of this class is forbidden. 
  60. * @since 1.0 
  61. */ 
  62. public function __wakeup() { 
  63. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-germanized' ), '1.0' ); 
  64.  
  65. /** 
  66. * Global getter 
  67. * @param string $key 
  68. * @return mixed 
  69. */ 
  70. public function __get( $key ) { 
  71. return $this->$key; 
  72.  
  73. /** 
  74. * adds some initialization hooks and inits WooCommerce Germanized 
  75. */ 
  76. public function __construct() { 
  77.  
  78. // Auto-load classes on demand 
  79. if ( function_exists( '__autoload' ) ) { 
  80. spl_autoload_register( '__autoload' ); 
  81.  
  82. spl_autoload_register( array( $this, 'autoload' ) ); 
  83.  
  84. $dependencies = apply_filters( 'woocommerce_gzd_dependencies_instance', WC_GZD_Dependencies::instance( $this ) ); 
  85.  
  86. if ( ! $dependencies->is_loadable() ) { 
  87. return; 
  88.  
  89. // Define constants 
  90. $this->define_constants(); 
  91.  
  92. $this->includes(); 
  93.  
  94. // Hooks 
  95. register_activation_hook( __FILE__, array( 'WC_GZD_Install', 'install' ) ); 
  96. add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) ); 
  97. add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 12 ); 
  98.  
  99. add_action( 'init', array( $this, 'init' ), 0 ); 
  100. add_action( 'init', array( 'WC_GZD_Shortcodes', 'init' ), 2 ); 
  101. add_action( 'init', array( $this, 'setup_compatibility' ), 15 ); 
  102.  
  103. add_action( 'woocommerce_init', array( $this, 'replace_woocommerce_product_factory' ), PHP_INT_MAX ); 
  104. // Set template filter directly after load to ensure wc_get_template finds templates 
  105. add_filter( 'woocommerce_locate_template', array( $this, 'filter_templates' ), PHP_INT_MAX, 3 ); 
  106.  
  107. $this->units = new WC_GZD_Units(); 
  108. $this->price_labels = new WC_GZD_Price_Labels(); 
  109.  
  110. // Loaded action 
  111. do_action( 'woocommerce_germanized_loaded' ); 
  112.  
  113.  
  114. /** 
  115. * Checks if is pro user 
  116. * @return boolean 
  117. */ 
  118. public function is_pro() { 
  119. return WC_GZD_Dependencies::instance()->is_plugin_activated( 'woocommerce-germanized-pro/woocommerce-germanized-pro.php' ); 
  120.  
  121. /** 
  122. * Init WooCommerceGermanized when WordPress initializes. 
  123. */ 
  124. public function init() { 
  125.  
  126. // Before init action 
  127. do_action( 'before_woocommerce_germanized_init' ); 
  128.  
  129. $this->load_plugin_textdomain(); 
  130.  
  131. if ( get_option( 'woocommerce_gzd_display_checkout_fallback' ) == 'yes' ) { 
  132. add_filter( 'woocommerce_germanized_filter_template', array( $this, 'set_checkout_fallback' ), 10, 3 ); 
  133.  
  134. add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_settings' ) ); 
  135.  
  136. add_filter( 'woocommerce_enqueue_styles', array( $this, 'add_styles' ) ); 
  137. // Load after WooCommerce Frontend scripts 
  138. add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ), 15 ); 
  139. add_action( 'wp_enqueue_scripts', array( $this, 'add_inline_styles' ) ); 
  140. add_action( 'wp_print_scripts', array( $this, 'localize_scripts' ), 5 ); 
  141. add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ) ); 
  142. add_filter( 'woocommerce_locate_core_template', array( $this, 'email_templates' ), 0, 3 ); 
  143. add_action( 'woocommerce_email_order_meta', array( $this, 'email_small_business_notice' ), 1 ); 
  144.  
  145. // Add better tax display to order totals 
  146. add_filter( 'woocommerce_get_order_item_totals', array( $this, 'order_item_totals' ), 0, 2 ); 
  147.  
  148. // Unsure wether this could lead to future problems - tax classes with same name wont be merged anylonger 
  149. // add_filter( 'woocommerce_rate_code', array( $this, 'prevent_tax_name_merge' ), PHP_INT_MAX, 2 ); 
  150. // Hide cart estimated text if chosen 
  151. add_action( 'woocommerce_cart_totals_after_order_total', array( $this, 'hide_cart_estimated_text' ) ); 
  152. add_action( 'woocommerce_after_cart_totals', array( $this, 'remove_cart_tax_zero_filter' ) ); 
  153.  
  154. // Add better WooCommerce shipping taxation 
  155. add_filter( 'woocommerce_package_rates', array( $this, 'replace_shipping_rate_class' ), 0, 2 ); 
  156.  
  157. // Payment gateways 
  158. add_filter( 'woocommerce_payment_gateways', array( $this, 'register_gateways' ) ); 
  159.  
  160. // Remove cart subtotal filter 
  161. add_action( 'template_redirect', array( $this, 'remove_cart_unit_price_filter' ) ); 
  162.  
  163. $this->emails = new WC_GZD_Emails(); 
  164.  
  165. // Init action 
  166. do_action( 'woocommerce_germanized_init' ); 
  167.  
  168. /** 
  169. * Auto-load WC_Germanized classes on demand to reduce memory consumption. 
  170. * @param mixed $class 
  171. * @return void 
  172. */ 
  173. public function autoload( $class ) { 
  174.  
  175. $path = $this->plugin_path() . '/includes/'; 
  176. $original_class = $class; 
  177. $class = strtolower( $class ); 
  178. $file = 'class-' . str_replace( '_', '-', $class ) . '.php'; 
  179.  
  180. if ( strpos( $class, 'wc_gzd_admin' ) !== false ) { 
  181. $path = $this->plugin_path() . '/includes/admin/'; 
  182. } elseif ( strpos( $class, 'wc_gzd_gateway_' ) !== false ) { 
  183. $path = $this->plugin_path() . '/includes/gateways/' . substr( str_replace( '_', '-', $class ), 15 ) . '/'; 
  184. } elseif ( strpos( $class, 'wc_gzd_trusted_shops' ) !== false ) { 
  185. $path = $this->plugin_path() . '/includes/trusted-shops/'; 
  186. } elseif ( strpos( $class, 'wc_gzd_compatibility' ) !== false ) { 
  187. $path = $this->plugin_path() . '/includes/compatibility/'; 
  188. } elseif ( strpos( $class, 'defuse\crypto' ) !== false ) { 
  189. $path = $this->plugin_path() . '/includes/gateways/direct-debit/libraries/php-encryption/'; 
  190. $file = ucfirst( str_replace( 'Defuse/Crypto/', '', str_replace( '\\', '/', $original_class ) ) . '.php' ); 
  191. } elseif ( strpos( $class, 'digitick\sepa' ) !== false ) { 
  192. $path = $this->plugin_path() . '/includes/gateways/direct-debit/libraries/php-sepa-xml/'; 
  193. $file = ucfirst( str_replace( 'Digitick/Sepa/', '', str_replace( '\\', '/', $original_class ) ) . '.php' ); 
  194. } elseif ( strpos( $class, 'ekomi\\' ) !== false ) { 
  195. $path = $this->plugin_path() . '/includes/libraries/Ekomi/'; 
  196. $file = ucfirst( str_replace( 'Ekomi/', '', str_replace( '\\', '/', $original_class ) ) . '.php' ); 
  197.  
  198. if ( $path && is_readable( $path . $file ) ) { 
  199. include_once( $path . $file ); 
  200. return; 
  201.  
  202.  
  203. /** 
  204. * Get the plugin url. 
  205. * @return string 
  206. */ 
  207. public function plugin_url() { 
  208. return untrailingslashit( plugins_url( '/', __FILE__ ) ); 
  209.  
  210. /** 
  211. * Get the plugin path. 
  212. * @return string 
  213. */ 
  214. public function plugin_path() { 
  215. return untrailingslashit( plugin_dir_path( __FILE__ ) ); 
  216.  
  217. /** 
  218. * Get WC Germanized template path 
  219. * @return string 
  220. */ 
  221. public function template_path() { 
  222. return apply_filters( 'woocommerce_gzd_template_path', 'woocommerce-germanized/' ); 
  223.  
  224. /** 
  225. * Get the language path 
  226. * @return string 
  227. */ 
  228. public function language_path() { 
  229. return $this->plugin_path() . '/i18n/languages'; 
  230.  
  231. /** 
  232. * Define WC_Germanized Constants 
  233. */ 
  234. private function define_constants() { 
  235. define( 'WC_GERMANIZED_PLUGIN_FILE', __FILE__ ); 
  236. define( 'WC_GERMANIZED_VERSION', $this->version ); 
  237.  
  238. /** 
  239. * Include required core files used in admin and on the frontend. 
  240. */ 
  241. private function includes() { 
  242.  
  243. include_once( 'includes/wc-gzd-core-functions.php' ); 
  244. include_once( 'includes/wc-gzd-legacy-functions.php' ); 
  245. include_once( 'includes/class-wc-gzd-install.php' ); 
  246.  
  247. if ( is_admin() ) { 
  248.  
  249. include_once( 'includes/admin/class-wc-gzd-admin.php' ); 
  250. include_once( 'includes/admin/class-wc-gzd-admin-welcome.php' ); 
  251. include_once( 'includes/admin/class-wc-gzd-admin-notices.php' ); 
  252. include_once( 'includes/admin/class-wc-gzd-admin-customer.php' ); 
  253. include_once( 'includes/admin/class-wc-gzd-admin-importer.php' ); 
  254.  
  255.  
  256. include_once( 'includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data.php' ); 
  257. include_once( 'includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data-variable.php' ); 
  258.  
  259. if ( defined( 'DOING_AJAX' ) ) { 
  260. $this->ajax_includes(); 
  261.  
  262. if ( ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) ) { 
  263. if ( did_action( 'woocommerce_loaded' ) ) { 
  264. $this->frontend_includes(); 
  265. } else { 
  266. add_action( 'woocommerce_loaded', array( $this, 'frontend_includes' ), 5 ); 
  267.  
  268. // Post types 
  269. include_once( 'includes/class-wc-gzd-post-types.php' ); 
  270. // Gateway manipulation 
  271. include_once( 'includes/class-wc-gzd-payment-gateways.php' ); 
  272. // Template priority 
  273. include_once( 'includes/class-wc-gzd-hook-priorities.php' ); 
  274.  
  275. // Abstracts 
  276. include_once( 'includes/abstracts/abstract-wc-gzd-product.php' ); 
  277. include_once( 'includes/abstracts/abstract-wc-gzd-taxonomy.php' ); 
  278. include_once( 'includes/abstracts/abstract-wc-gzd-compatibility.php' ); 
  279.  
  280. // API 
  281. include_once( 'includes/api/class-wc-gzd-rest-api.php' ); 
  282.  
  283. include_once( 'includes/wc-gzd-cart-functions.php' ); 
  284. include_once( 'includes/wc-gzd-order-functions.php' ); 
  285.  
  286. include_once( 'includes/class-wc-gzd-checkout.php' ); 
  287. include_once( 'includes/class-wc-gzd-dhl-parcel-shops.php' ); 
  288. include_once( 'includes/class-wc-gzd-customer-helper.php' ); 
  289. include_once( 'includes/class-wc-gzd-virtual-vat-helper.php' ); 
  290.  
  291. $this->setup_trusted_shops(); 
  292. $this->ekomi = new WC_GZD_Ekomi(); 
  293.  
  294.  
  295. public function setup_compatibility() { 
  296.  
  297. $plugins = apply_filters( 'woocommerce_gzd_compatibilities', array( 'wpml', 'woocommerce-subscriptions' ) ); 
  298.  
  299. foreach ( $plugins as $comp ) { 
  300.  
  301. $classname = str_replace( ' ', '_', 'WC_GZD_Compatibility_' . ucwords( str_replace( '-', ' ', $comp ) ) ); 
  302.  
  303. if ( class_exists( $classname ) ) { 
  304. $this->compatibilities[ $comp ] = new $classname(); 
  305.  
  306.  
  307. /** 
  308. * Include required ajax files. 
  309. */ 
  310. public function ajax_includes() { 
  311. include_once( 'includes/class-wc-gzd-ajax.php' ); 
  312.  
  313. /** 
  314. * Include required frontend files. 
  315. */ 
  316. public function frontend_includes() { 
  317. include_once( 'includes/wc-gzd-template-hooks.php' ); 
  318.  
  319. /** 
  320. * Function used to Init WooCommerceGermanized Template Functions - This makes them pluggable by plugins and themes. 
  321. */ 
  322. public function include_template_functions() { 
  323. if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { 
  324. include_once( 'includes/wc-gzd-template-functions.php' ); 
  325.  
  326. /** 
  327. * Filter WooCommerce Templates to look into /templates before looking within theme folder 
  328. * @param string $template 
  329. * @param string $template_name 
  330. * @param string $template_path 
  331. * @return string 
  332. */ 
  333. public function filter_templates( $template, $template_name, $template_path ) { 
  334. $template_path = $this->template_path(); 
  335.  
  336. if ( ! isset( $GLOBALS['wc_gzd_template_name'] ) || empty( $GLOBALS['wc_gzd_template_name'] ) || ! is_array( $GLOBALS['wc_gzd_template_name'] ) ) { 
  337. $GLOBALS['wc_gzd_template_name'] = array(); 
  338.  
  339. $GLOBALS['wc_gzd_template_name'][] = $template_name; 
  340.  
  341. // Check Theme 
  342. $theme_template = locate_template( 
  343. array( 
  344. trailingslashit( $template_path ) . $template_name,  
  345. $template_name,  
  346. ); 
  347.  
  348. $template_name = apply_filters( 'woocommerce_gzd_template_name', $template_name ); 
  349.  
  350. // Load Default 
  351. if ( ! $theme_template && file_exists( apply_filters( 'woocommerce_gzd_default_plugin_template', $this->plugin_path() . '/templates/' . $template_name, $template_name ) ) ) { 
  352. $template = apply_filters( 'woocommerce_gzd_default_plugin_template', $this->plugin_path() . '/templates/' . $template_name, $template_name ); 
  353. } elseif ( $theme_template ) { 
  354. $template = $theme_template; 
  355.  
  356. return apply_filters( 'woocommerce_germanized_filter_template', $template, $template_name, $template_path ); 
  357.  
  358. /** 
  359. * Get templates which are legally critical 
  360. * @return array 
  361. */ 
  362. public function get_critical_templates() { 
  363. return apply_filters( 'woocommerce_gzd_important_templates', array() ); 
  364.  
  365. /** 
  366. * Sets review-order.php fallback (if activated) by filtering template name. 
  367. * @param string $template_name 
  368. * @return string 
  369. */ 
  370. public function set_checkout_fallback( $template, $template_name, $template_path ) { 
  371.  
  372. $path = WC()->plugin_path() . '/templates/'; 
  373.  
  374. if ( strstr( $template_name, 'review-order.php' ) ) { 
  375. return trailingslashit( $path ) . 'checkout/review-order.php'; 
  376. } elseif ( strstr( $template_name, 'form-checkout.php' ) ) { 
  377. return trailingslashit( $path ) . 'checkout/form-checkout.php'; 
  378.  
  379. return $template; 
  380.  
  381. /** 
  382. * Overload product factory to inject gzd_product 
  383. */ 
  384. public function replace_woocommerce_product_factory() { 
  385. WC()->product_factory = new WC_GZD_Product_Factory(); 
  386.  
  387. /** 
  388. * Replace default WC_Shipping_Rate to enable exact taxation for shipping costs 
  389. * @param array $rates containing WC_Shipping_Rate objects 
  390. * @param WC_Shipping_Rate $rate current object 
  391. * @return array 
  392. */ 
  393. public function replace_shipping_rate_class( $rates, $rate ) { 
  394.  
  395. if ( get_option( 'woocommerce_gzd_shipping_tax' ) !== 'yes' ) { 
  396. return $rates; 
  397.  
  398. foreach ( $rates as $key => $rate ) { 
  399. // Check for instance to make sure calculation is not done for multiple times 
  400. if ( ! $rate instanceof WC_GZD_Shipping_Rate ) { 
  401. $rates[ $key ] = new WC_GZD_Shipping_Rate( $rate ); 
  402.  
  403. return $rates; 
  404.  
  405. /** 
  406. * Calls a filter to temporarily set cart tax to zero. This is only done to hide the cart tax estimated text. 
  407. * Filter is being remove right after get_cart_tax - check has been finished within cart-totals.php 
  408. */ 
  409. public function hide_cart_estimated_text() { 
  410. if ( get_option( 'woocommerce_gzd_display_hide_cart_tax_estimated' ) == 'yes' ) { 
  411. add_filter( 'woocommerce_get_cart_tax', array( $this, 'set_cart_tax_zero' ) ); 
  412.  
  413. /** 
  414. * This will set the cart tax to zero 
  415. * @param float $tax current's cart tax 
  416. * @return int 
  417. */ 
  418. public function set_cart_tax_zero( $tax ) { 
  419. return 0; 
  420.  
  421. /** 
  422. * Removes the zero cart tax filter after get_cart_tax has been finished 
  423. */ 
  424. public function remove_cart_tax_zero_filter() { 
  425. if ( get_option( 'woocommerce_gzd_display_hide_cart_tax_estimated' ) == 'yes' ) { 
  426. remove_filter( 'woocommerce_get_cart_tax', array( $this, 'set_cart_tax_zero' ) ); 
  427.  
  428. /** 
  429. * Load WooCommerce Germanized Product Classes instead of WooCommerce builtin Product Classes 
  430. * @param string $classname 
  431. * @param string $product_type 
  432. * @param string $post_type 
  433. * @param integer $product_id 
  434. * @return string 
  435. */ 
  436. public function filter_product_classes( $classname, $product_type, $post_type, $product_id ) { 
  437. $gzd_classname = str_replace( 'WC', 'WC_GZD', $classname ); 
  438. if ( class_exists( $gzd_classname ) ) { 
  439. $classname = $gzd_classname; 
  440. return $classname; 
  441.  
  442. /** 
  443. * Load Localisation files. 
  444. * Note: the first-loaded translation file overrides any following ones if the same translation is present. 
  445. * Frontend/global Locales found in: 
  446. * - WP_LANG_DIR/woocommerce-germanized/woocommerce-germanized-LOCALE.mo 
  447. * - WP_LANG_DIR/plugins/woocommerce-germanized-LOCALE.mo 
  448. */ 
  449. public function load_plugin_textdomain() { 
  450. $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-germanized' ); 
  451.  
  452. load_textdomain( 'woocommerce-germanized', trailingslashit( WP_LANG_DIR ) . 'woocommerce-germanized/woocommerce-germanized-' . $locale . '.mo' ); 
  453. load_plugin_textdomain( 'woocommerce-germanized', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages/' ); 
  454.  
  455. /** 
  456. * Show action links on the plugin screen 
  457. * @param mixed $links 
  458. * @return array 
  459. */ 
  460. public function action_links( $links ) { 
  461. return array_merge( array( 
  462. '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=germanized' ) . '">' . __( 'Settings', 'woocommerce-germanized' ) . '</a>',  
  463. ), $links ); 
  464.  
  465. /** 
  466. * Add styles to frontend 
  467. * @param array $styles 
  468. */ 
  469. public function add_styles( $styles ) { 
  470. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  471.  
  472. $styles['woocommerce-gzd-layout'] = array( 
  473. 'src' => str_replace( array( 'http:', 'https:' ), '', WC_germanized()->plugin_url() ) . '/assets/css/woocommerce-gzd-layout' . $suffix . '.css',  
  474. 'deps' => '',  
  475. 'version' => WC_GERMANIZED_VERSION,  
  476. 'media' => 'all',  
  477. ); 
  478.  
  479. return $styles; 
  480.  
  481. /** 
  482. * Adds woocommerce checkout table background highlight color as inline css 
  483. */ 
  484. public function add_inline_styles() { 
  485. $color = ( get_option( 'woocommerce_gzd_display_checkout_table_color' ) ? get_option( 'woocommerce_gzd_display_checkout_table_color' ) : '#eee' ); 
  486. $custom_css = ".woocommerce-checkout .shop_table { background-color: $color; }"; 
  487. wp_add_inline_style( 'woocommerce-gzd-layout', $custom_css ); 
  488.  
  489. /** 
  490. * Add Scripts to frontend 
  491. */ 
  492. public function add_scripts() { 
  493. global $post; 
  494.  
  495. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  496. $assets_path = str_replace( array( 'http:', 'https:' ), '', WC_germanized()->plugin_url() ) . '/assets/'; 
  497. $frontend_script_path = $assets_path . 'js/'; 
  498.  
  499. if ( is_page() && is_object( $post ) && has_shortcode( $post->post_content, 'revocation_form' ) ) { 
  500. wp_enqueue_script( 'wc-gzd-revocation', $frontend_script_path . 'revocation' . $suffix . '.js', array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), WC_GERMANIZED_VERSION, true ); 
  501.  
  502. if ( is_checkout() ) { 
  503.  
  504. wp_enqueue_script( 'wc-gzd-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 
  505. 'jquery',  
  506. 'wc-checkout',  
  507. ), WC_GERMANIZED_VERSION, true ); 
  508.  
  509.  
  510. if ( is_singular( 'product' ) ) { 
  511. $product = wc_get_product( $post->ID ); 
  512. if ( $product && $product->is_type( 'variable' ) ) { 
  513. // Enqueue variation scripts 
  514. wp_enqueue_script( 'wc-gzd-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery', 'woocommerce', 'wc-add-to-cart-variation' ), WC_GERMANIZED_VERSION, true ); 
  515.  
  516. do_action( 'woocommerce_gzd_registered_scripts', $suffix, $frontend_script_path, $assets_path ); 
  517.  
  518. /** 
  519. * Localize Script to enable AJAX 
  520. */ 
  521. public function localize_scripts() { 
  522. global $wp; 
  523. $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; 
  524.  
  525. if ( wp_script_is( 'wc-gzd-revocation' ) ) { 
  526. wp_localize_script( 'wc-gzd-revocation', 'wc_gzd_revocation_params', apply_filters( 'wc_gzd_revocation_params', array( 
  527. 'ajax_url' => WC()->ajax_url(),  
  528. 'ajax_loader_url' => apply_filters( 'woocommerce_ajax_loader_url', $assets_path . 'images/ajax-loader@2x.gif' ),  
  529. ) ) ); 
  530. } else if ( wp_script_is( 'wc-gzd-add-to-cart-variation' ) ) { 
  531. wp_localize_script( 'wc-gzd-add-to-cart-variation', 'wc_gzd_add_to_cart_variation_params', apply_filters( 'woocommerce_gzd_add_to_cart_variation_params', array( 
  532. 'wrapper' => '.type-product',  
  533. ) ) ); 
  534.  
  535. do_action( 'woocommerce_gzd_localized_scripts', $assets_path ); 
  536.  
  537. /** 
  538. * Add WooCommerce Germanized Settings Tab 
  539. * @param array $integrations 
  540. * @return array 
  541. */ 
  542. public function add_settings( $integrations ) { 
  543. include_once( 'includes/admin/settings/class-wc-gzd-settings-germanized.php' ); 
  544. $integrations[] = new WC_GZD_Settings_Germanized(); 
  545. return $integrations; 
  546.  
  547. /** 
  548. * Add small business global Email Footer 
  549. */ 
  550. public function email_small_business_notice() { 
  551. if ( get_option( 'woocommerce_gzd_small_enterprise' ) == 'yes' ) { 
  552. wc_get_template( 'global/small-business-info.php' ); 
  553.  
  554. /** 
  555. * PHP 5.3 backwards compatibility for getting date diff in days 
  556. * @param string $from date from 
  557. * @param string $to date to 
  558. * @return array 
  559. */ 
  560. public function get_date_diff( $from, $to ) { 
  561. $diff = abs( strtotime( $to ) - strtotime( $from ) ); 
  562. return array( 
  563. 'd' => floor( $diff / ( 60 * 60 * 24 ) ),  
  564. ); 
  565.  
  566. /** 
  567. * Add Custom Email templates 
  568. * @param array $mails 
  569. * @return array 
  570. */ 
  571. public function add_emails( $mails ) { 
  572. $mails['WC_GZD_Email_Customer_Paid_For_Order'] = include 'includes/emails/class-wc-gzd-email-customer-paid-for-order.php'; 
  573. $mails['WC_GZD_Email_Customer_New_Account_Activation'] = include 'includes/emails/class-wc-gzd-email-customer-new-account-activation.php'; 
  574. $mails['WC_GZD_Email_Customer_Revocation'] = include 'includes/emails/class-wc-gzd-email-customer-revocation.php'; 
  575. $mails['WC_GZD_Email_Customer_Ekomi'] = include 'includes/emails/class-wc-gzd-email-customer-ekomi.php'; 
  576. $mails['WC_GZD_Email_Customer_Trusted_Shops'] = include 'includes/emails/class-wc-gzd-email-customer-trusted-shops.php'; 
  577. return $mails; 
  578.  
  579. /** 
  580. * Filter Email template to include WooCommerce Germanized template files 
  581. * @param string $core_file 
  582. * @param string $template 
  583. * @param string $template_base 
  584. * @return string 
  585. */ 
  586. public function email_templates( $core_file, $template, $template_base ) { 
  587.  
  588. if ( ! file_exists( $template_base . $template ) && file_exists( $this->plugin_path() . '/templates/' . $template ) ) { 
  589. $core_file = $this->plugin_path() . '/templates/' . $template; 
  590.  
  591. return apply_filters( 'woocommerce_germanized_email_template_hook', $core_file, $template, $template_base ); 
  592.  
  593. public function register_gateways( $gateways ) { 
  594.  
  595. // Do only load gateway for PHP >= 5.3 because of Namespaces 
  596. if ( version_compare( phpversion(), '5.3', '>=' ) ) { 
  597. $gateways[] = 'WC_GZD_Gateway_Direct_Debit'; 
  598.  
  599. $gateways[] = 'WC_GZD_Gateway_Invoice'; 
  600.  
  601. return $gateways; 
  602.  
  603.  
  604. /** 
  605. * Improve tax display within order totals 
  606. * @param array $order_totals 
  607. * @param object $order 
  608. * @return array 
  609. */ 
  610. public function order_item_totals( $order_totals, $order ) { 
  611.  
  612. // Set to formatted total without displaying tax info behind the price 
  613. $order_totals['order_total']['value'] = $order->get_formatted_order_total(); 
  614.  
  615. // Tax for inclusive prices 
  616. if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) && 'incl' == get_option( 'woocommerce_tax_display_cart' ) ) { 
  617.  
  618. $tax_array = array(); 
  619. if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) { 
  620.  
  621. foreach ( $order->get_tax_totals() as $code => $tax ) { 
  622.  
  623. $tax->rate = WC_Tax::get_rate_percent( $tax->rate_id ); 
  624.  
  625. if ( ! isset( $tax_array[ $tax->rate ] ) ) { 
  626. $tax_array[ $tax->rate ] = array( 
  627. 'tax' => $tax,  
  628. 'amount' => $tax->amount,  
  629. 'contains' => array( $tax ),  
  630. ); 
  631. } else { 
  632. array_push( $tax_array[ $tax->rate ]['contains'], $tax ); 
  633. $tax_array[ $tax->rate ]['amount'] += $tax->amount; 
  634. } else { 
  635.  
  636. $base_rate = array_values( WC_Tax::get_shop_base_rate() ); 
  637. $base_rate = (object) $base_rate[0]; 
  638. $base_rate->rate = $base_rate->rate; 
  639. $tax_array[] = array( 
  640. 'tax' => $base_rate,  
  641. 'contains' => array( $base_rate ),  
  642. 'amount' => $order->get_total_tax(),  
  643. ); 
  644.  
  645. if ( ! empty( $tax_array ) ) { 
  646. foreach ( $tax_array as $tax ) { 
  647.  
  648. $order_totals[ 'tax_' . WC_Tax::get_rate_code( $tax['tax']->rate_id ) ] = array( 
  649. 'label' => ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ? sprintf( __( 'incl. %s%% VAT', 'woocommerce-germanized' ), wc_gzd_format_tax_rate_percentage( $tax['tax']->rate ) ) : __( 'incl. VAT', 'woocommerce-germanized' ) ),  
  650. 'value' => wc_price( $tax['amount'] ),  
  651. ); 
  652. }// End if(). 
  653.  
  654. return $order_totals; 
  655.  
  656. /** 
  657. * Remove cart unit price subtotal filter 
  658. */ 
  659. public function remove_cart_unit_price_filter() { 
  660. if ( is_cart() ) { 
  661. remove_filter( 'woocommerce_cart_item_subtotal', 'wc_gzd_cart_product_unit_price', 0, 2 ); 
  662.  
  663. /** 
  664. * Prevent tax class merging. Could lead to future problems - not yet implemented 
  665. * @param string $code tax class code 
  666. * @param int $rate_id 
  667. * @return string unique tax class code 
  668. */ 
  669. public function prevent_tax_name_merge( $code, $rate_id ) { 
  670. return $code . '-' . $rate_id; 
  671.  
  672. /** 
  673. * Initialize Trusted Shops Module 
  674. */ 
  675. private function setup_trusted_shops() { 
  676. // Initialize Trusted Shops module 
  677. $this->trusted_shops = new WC_GZD_Trusted_Shops( $this, array( 
  678. 'prefix' => 'GZD_',  
  679. 'et_params' => array( 
  680. 'utm_campaign' => 'shopsoftware',  
  681. 'utm_content' => 'WOOCOMMERCEGERMANIZED',  
  682. ),  
  683. 'signup_params' => array( 
  684. 'utm_source' => 'woocommerce-germanized',  
  685. 'utm_campaign' => 'woocommerce-germanized',  
  686. ),  
  687. 'urls' => array( 
  688. 'integration' => 'http://www.trustedshops.de/shopbetreiber/integration/shopsoftware-integration/woocommerce-germanized/',  
  689. 'signup' => 'http://www.trustbadge.com/de/Preise/',  
  690. 'trustbadge_custom' => 'http://www.trustedshops.de/shopbetreiber/integration/trustbadge/trustbadge-custom/',  
  691. 'reviews' => 'http://www.trustedshops.de/shopbetreiber/integration/product-reviews/',  
  692. ),  
  693. );