WC_Correios

WooCommerce Correios main class.

Defined (1)

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

/woocommerce-correios.php  
  1. class WC_Correios { 
  2.  
  3. /** 
  4. * Plugin version. 
  5. * @var string 
  6. */ 
  7. const VERSION = '3.3.0'; 
  8.  
  9. /** 
  10. * Instance of this class. 
  11. * @var object 
  12. */ 
  13. protected static $instance = null; 
  14.  
  15. /** 
  16. * Initialize the plugin public actions. 
  17. */ 
  18. private function __construct() { 
  19. add_action( 'init', array( $this, 'load_plugin_textdomain' ), -1 ); 
  20.  
  21. // Checks with WooCommerce is installed. 
  22. if ( class_exists( 'WC_Integration' ) ) { 
  23. $this->includes(); 
  24.  
  25. if ( is_admin() ) { 
  26. $this->admin_includes(); 
  27.  
  28. add_filter( 'woocommerce_integrations', array( $this, 'include_integrations' ) ); 
  29. add_filter( 'woocommerce_shipping_methods', array( $this, 'include_methods' ) ); 
  30. add_filter( 'woocommerce_email_classes', array( $this, 'include_emails' ) ); 
  31. } else { 
  32. add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); 
  33.  
  34. /** 
  35. * Return an instance of this class. 
  36. * @return object A single instance of this class. 
  37. */ 
  38. public static function get_instance() { 
  39. // If the single instance hasn't been set, set it now. 
  40. if ( null === self::$instance ) { 
  41. self::$instance = new self; 
  42.  
  43. return self::$instance; 
  44.  
  45. /** 
  46. * Load the plugin text domain for translation. 
  47. */ 
  48. public function load_plugin_textdomain() { 
  49. load_plugin_textdomain( 'woocommerce-correios', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  50.  
  51. /** 
  52. * Includes. 
  53. */ 
  54. private function includes() { 
  55. include_once dirname( __FILE__ ) . '/includes/wc-correios-functions.php'; 
  56. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-install.php'; 
  57. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-package.php'; 
  58. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-webservice.php'; 
  59. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-webservice-international.php'; 
  60. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-autofill-addresses.php'; 
  61. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-tracking-history.php'; 
  62. include_once dirname( __FILE__ ) . '/includes/class-wc-correios-rest-api.php'; 
  63.  
  64. // Integration. 
  65. include_once dirname( __FILE__ ) . '/includes/integrations/class-wc-correios-integration.php'; 
  66.  
  67. // Shipping methods. 
  68. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.6.0', '>=' ) ) { 
  69. include_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-correios-shipping.php'; 
  70. include_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-correios-shipping-carta.php'; 
  71. include_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-correios-shipping-impresso.php'; 
  72. include_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-correios-shipping-international.php'; 
  73. foreach ( glob( plugin_dir_path( __FILE__ ) . '/includes/shipping/*.php' ) as $filename ) { 
  74. include_once $filename; 
  75.   
  76. // Update settings to 3.0.0 when using WooCommerce 2.6.0. 
  77. WC_Correios_Install::upgrade_300_from_wc_260(); 
  78. } else { 
  79. include_once dirname( __FILE__ ) . '/includes/shipping/class-wc-correios-shipping-legacy.php'; 
  80.   
  81. // Update to 3.0.0. 
  82. WC_Correios_Install::upgrade_300(); 
  83.   
  84. /** 
  85. * Admin includes. 
  86. */ 
  87. private function admin_includes() { 
  88. include_once dirname( __FILE__ ) . '/includes/admin/class-wc-correios-admin-orders.php'; 
  89.  
  90. /** 
  91. * Include Correios integration to WooCommerce. 
  92. * @param array $integrations Default integrations. 
  93. * @return array 
  94. */ 
  95. public function include_integrations( $integrations ) { 
  96. $integrations[] = 'WC_Correios_Integration'; 
  97.  
  98. return $integrations; 
  99.  
  100. /** 
  101. * Include Correios shipping methods to WooCommerce. 
  102. * @param array $methods Default shipping methods. 
  103. * @return array 
  104. */ 
  105. public function include_methods( $methods ) { 
  106. // Legacy method. 
  107. $methods['correios-legacy'] = 'WC_Correios_Shipping_Legacy'; 
  108.  
  109. // New methods. 
  110. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.6.0', '>=' ) ) { 
  111. $methods['correios-pac'] = 'WC_Correios_Shipping_PAC'; 
  112. $methods['correios-sedex'] = 'WC_Correios_Shipping_SEDEX'; 
  113. $methods['correios-sedex10-envelope'] = 'WC_Correios_Shipping_SEDEX_10_Envelope'; 
  114. $methods['correios-sedex10-pacote'] = 'WC_Correios_Shipping_SEDEX_10_Pacote'; 
  115. $methods['correios-sedex12'] = 'WC_Correios_Shipping_SEDEX_12'; 
  116. $methods['correios-sedex-hoje'] = 'WC_Correios_Shipping_SEDEX_Hoje'; 
  117. $methods['correios-esedex'] = 'WC_Correios_Shipping_ESEDEX'; 
  118. $methods['correios-carta-registrada'] = 'WC_Correios_Shipping_Carta_Registrada'; 
  119. $methods['correios-impresso-normal'] = 'WC_Correios_Shipping_Impresso_Normal'; 
  120. $methods['correios-impresso-urgente'] = 'WC_Correios_Shipping_Impresso_Urgente'; 
  121. $methods['correios-mercadoria-expressa'] = 'WC_Correios_Shipping_Mercadoria_Expressa'; 
  122. $methods['correios-mercadoria-economica'] = 'WC_Correios_Shipping_Mercadoria_Economica'; 
  123. $methods['correios-leve-internacional'] = 'WC_Correios_Shipping_Leve_Internacional'; 
  124.  
  125. $old_options = get_option( 'woocommerce_correios_settings' ); 
  126. if ( empty( $old_options ) ) { 
  127. unset( $methods['correios-legacy'] ); 
  128.  
  129. return $methods; 
  130.  
  131. /** 
  132. * Include emails. 
  133. * @param array $emails Default emails. 
  134. * @return array 
  135. */ 
  136. public function include_emails( $emails ) { 
  137. if ( ! isset( $emails['WC_Correios_Tracking_Email'] ) ) { 
  138. $emails['WC_Correios_Tracking_Email'] = include( dirname( __FILE__ ) . '/includes/emails/class-wc-correios-tracking-email.php' ); 
  139.  
  140. return $emails; 
  141.  
  142. /** 
  143. * WooCommerce fallback notice. 
  144. */ 
  145. public function woocommerce_missing_notice() { 
  146. include_once dirname( __FILE__ ) . '/includes/admin/views/html-admin-missing-dependencies.php'; 
  147.  
  148. /** 
  149. * Get main file. 
  150. * @return string 
  151. */ 
  152. public static function get_main_file() { 
  153. return __FILE__; 
  154.  
  155. /** 
  156. * Get plugin path. 
  157. * @return string 
  158. */ 
  159. public static function get_plugin_path() { 
  160. return plugin_dir_path( __FILE__ ); 
  161.  
  162. /** 
  163. * Get templates path. 
  164. * @return string 
  165. */ 
  166. public static function get_templates_path() { 
  167. return self::get_plugin_path() . 'templates/';