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