WC_MercadoPago

WooCommerce MercadoPago main class.

Defined (1)

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

/woocommerce-mercadopago.php  
  1. class WC_MercadoPago { 
  2.  
  3. /** 
  4. * Plugin version. 
  5. * @var string 
  6. */ 
  7. const VERSION = '3.0.0'; 
  8.  
  9. /** 
  10. * Instance of this class. 
  11. * @var object 
  12. */ 
  13. protected static $instance = null; 
  14.  
  15. /** 
  16. * Initialize the plugin. 
  17. */ 
  18. private function __construct() { 
  19. add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 
  20.  
  21. // Checks with WooCommerce is installed. 
  22. if ( class_exists( 'WC_Payment_Gateway' ) ) { 
  23. $this->includes(); 
  24.  
  25. add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); 
  26. add_filter( 'woocommerce_cancel_unpaid_order', array( $this, 'stop_cancel_unpaid_orders' ), 10, 2 ); 
  27. add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); 
  28. } else { 
  29. add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); 
  30.  
  31. /** 
  32. * Return an instance of this class. 
  33. * @return object A single instance of this class. 
  34. */ 
  35. public static function get_instance() { 
  36. // If the single instance hasn't been set, set it now. 
  37. if ( null == self::$instance ) { 
  38. self::$instance = new self; 
  39.  
  40. return self::$instance; 
  41.  
  42. /** 
  43. * Load the plugin text domain for translation. 
  44. */ 
  45. public function load_plugin_textdomain() { 
  46. load_plugin_textdomain( 'woocommerce-mercadopago', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  47.  
  48. /** 
  49. * Includes. 
  50. */ 
  51. private function includes() { 
  52. include_once 'includes/class-wc-mercadopago-api.php'; 
  53. include_once 'includes/class-wc-mercadopago-gateway.php'; 
  54.  
  55. /** 
  56. * Add the gateway to WooCommerce. 
  57. * @param array $methods WooCommerce payment methods. 
  58. * @return array Payment methods with MercadoPago. 
  59. */ 
  60. public function add_gateway( $methods ) { 
  61. $methods[] = 'WC_MercadoPago_Gateway'; 
  62.  
  63. return $methods; 
  64.  
  65. /** 
  66. * Stop cancel unpaid MercadoPago orders. 
  67. * @param bool $cancel If should cancel the order. 
  68. * @param WC_Order $order Order data. 
  69. * @return bool 
  70. */ 
  71. public function stop_cancel_unpaid_orders( $cancel, $order ) { 
  72. if ( 'mercadopago' === $order->payment_method ) { 
  73. return false; 
  74.  
  75. return $cancel; 
  76.  
  77. /** 
  78. * Action links. 
  79. * @param array $links Plugin action links. 
  80. * @return array 
  81. */ 
  82. public function plugin_action_links( $links ) { 
  83. $plugin_links = array(); 
  84.  
  85. $plugin_links[] = '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_mercadopago_gateway' ) ) . '">' . esc_html__( 'Settings', 'woocommerce-mercadopago' ) . '</a>'; 
  86.  
  87. return array_merge( $plugin_links, $links ); 
  88.  
  89. /** 
  90. * WooCommerce fallback notice. 
  91. */ 
  92. public function woocommerce_missing_notice() { 
  93. include 'includes/admin/views/html-admin-missing-dependencies.php';