diff --git a/azpay-woocommerce/azpay-woocommerce.php b/azpay-woocommerce/azpay-woocommerce.php index e8b4c71..ecd4823 100755 --- a/azpay-woocommerce/azpay-woocommerce.php +++ b/azpay-woocommerce/azpay-woocommerce.php @@ -1,19 +1,19 @@ . * * @package WC_azpay @@ -37,7 +37,7 @@ class WC_azpay { * * @var string */ - const VERSION = '1.0.3'; + const VERSION = '1.0.4'; /** * Instance of this class. @@ -93,12 +93,109 @@ private function __construct() { add_action( 'plugins_loaded', array($this, 'azpay_update_db_check' ) ); add_action( 'init', array($this, 'register_authorized_order_status' ) ); add_filter( 'wc_order_statuses', array($this,'add_authorized_to_order_statuses' ) ); + + add_filter( 'woocommerce_product_data_tabs', array( $this, 'woocommerce_product_data_tab') , 99 , 1 ); + add_action( 'woocommerce_product_data_panels', array( $this, 'woocommerce_product_custom_fields' )); + add_action( 'woocommerce_process_product_meta', array( $this, 'woocommerce_product_custom_fields_save' ) ); } else { add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); } } + function woocommerce_product_data_tab( $product_data_tabs ) { + $product_data_tabs['azpay_recurrent'] = array( + 'label' => __( 'Recorrência', 'azpay' ), + 'target' => 'azpay_recurrent_tab', + ); + return $product_data_tabs; + } + + function woocommerce_product_custom_fields() + { + global $woocommerce, $post; + echo '
'; + + woocommerce_wp_select( + array( + 'id' => 'azpay_product_recurrent', + 'placeholder' => 'Produto recorrente?', + 'label' => __('Produto recorrente?', 'woocommerce'), + 'desc_tip' => 'true', + 'options' => array( + 'no' => 'Não', + 'yes' => 'Sim', + ) + ) + ); + + woocommerce_wp_select( + array( + 'id' => 'azpay_subscription_period', + 'placeholder' => 'Produto recorrente?', + 'label' => __('Todo(a)?', 'woocommerce'), + 'desc_tip' => 'true', + 'options' => array( + 'day' => 'Dia', + 'week' => 'Semana', + 'month' => 'Mês', + 'year' => 'Ano', + ) + ) + ); + + // Custom Product Text Field + woocommerce_wp_text_input( + array( + 'id' => 'azpay_subscription_days', + 'placeholder' => 'Expira após (em dias)', + 'label' => __('Expira após (em dias)', 'woocommerce'), + 'type' => 'number', + 'custom_attributes' => array( + 'step' => 'any', + 'min' => '0' + ) + ) + ); + + + + //Custom Product Number Field + woocommerce_wp_text_input( + array( + 'id' => 'azpay_subscription_frequency', + 'placeholder' => 'Frequência / a cada', + 'label' => __('Frequência / a cada', 'woocommerce'), + 'type' => 'number', + 'custom_attributes' => array( + 'step' => 'any', + 'min' => '0' + ) + ) + ); + echo '
'; + } + + function woocommerce_product_custom_fields_save($post_id) + { + $azpay_product_recurrent = $_POST['azpay_product_recurrent']; + if (!empty($azpay_product_recurrent)) + update_post_meta($post_id, 'azpay_product_recurrent', esc_attr($azpay_product_recurrent)); + // Custom Product Text Field + $azpay_subscription_period = $_POST['azpay_subscription_period']; + if (!empty($azpay_subscription_period)) + update_post_meta($post_id, 'azpay_subscription_period', esc_attr($azpay_subscription_period)); + // Custom Product Number Field + $azpay_subscription_days = $_POST['azpay_subscription_days']; + if (!empty($azpay_subscription_days)) + update_post_meta($post_id, 'azpay_subscription_days', esc_attr($azpay_subscription_days)); + // Custom Product Textarea Field + $azpay_subscription_frequency = $_POST['azpay_subscription_frequency']; + if (!empty($azpay_subscription_frequency)) + update_post_meta($post_id, 'azpay_subscription_frequency', esc_html($azpay_subscription_frequency)); + } + + function child_plugin_has_parent_plugin() { if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( 'woocommerce-extra-checkout-fields-for-brazil/woocommerce-extra-checkout-fields-for-brazil.php' ) ) { include_once dirname( __FILE__ ) . '/includes/views/notices/html-notice-extra-fields-missing.php'; @@ -515,14 +612,14 @@ public function load_plugin_textdomain() { * Includes. */ private function includes() { - include_once dirname(__FILE__).'/includes/class-wc-azpay-product-type.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-xml.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-helper.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-api.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-debit-gateway.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-credit-gateway.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-slip-gateway.php'; - include_once dirname(__FILE__).'/includes/class-wc-azpay-transfer-gateway.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-product-type.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-xml.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-helper.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-api.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-debit-gateway.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-credit-gateway.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-slip-gateway.php'; + include_once dirname( __FILE__ ) . '/includes/class-wc-azpay-transfer-gateway.php'; } /** @@ -530,7 +627,7 @@ private function includes() { * * @param array $methods WooCommerce payment methods. * - * @return array Payment methods with Azpay. + * @return array Payment methods with azpay. */ public function add_gateway( $methods ) { array_push( $methods, 'azpay\payment\WC_azpay_Debit_Gateway', 'azpay\payment\WC_azpay_Credit_Gateway', 'azpay\payment\WC_azpay_Slip_Gateway', 'azpay\payment\WC_azpay_Transfer_Gateway'); @@ -583,7 +680,7 @@ private function upgrade() { 'title' => __( 'Debit Card', 'azpay-woocommerce' ), 'description' => $options['description'], 'merchant_id' => __( 'Merchant ID', 'azpay-woocommerce' ), - 'merchant_key' => __( 'Merchant Key', 'azpay-woocommerce' ), + 'merchant_key' => __( 'Merchant Key', 'azpay-woocommerce' ), 'environment' => $options['environment'], 'methods' => $debit_methods, 'debit_discount' => $options['debit_discount'], @@ -615,7 +712,7 @@ public function register_scripts() { wp_register_style( 'wc-azpay-checkout-icons', plugins_url( 'assets/css/checkout-icons' . $suffix . '.css', __FILE__ ), array(), WC_azpay::VERSION ); wp_register_style( 'wc-azpay-checkout-webservice', plugins_url( 'assets/css/checkout-webservice' . $suffix . '.css', __FILE__ ), array(), WC_azpay::VERSION ); - wp_enqueue_script( 'wc-azpay-checkout-ws', plugins_url( 'assets/js/checkout-ws.js', __FILE__ ), array( 'jquery' ), WC_azpay::VERSION, true ); + wp_enqueue_script( 'wc-azpay-checkout-ws', plugins_url( 'assets/js/checkout-ws.js', __FILE__ ), array( 'jquery' ), time(), true ); } @@ -664,7 +761,8 @@ function azpay_unset_gateway_subscription( $available_gateways ) { if ($order_id <= 0){ foreach ( WC()->cart->get_cart_contents() as $key => $values ) { $_product = $values['data']; - if ($_product->is_type('azpay_subscription')){ + $azpay_recurrent = get_post_meta($values['product_id'], 'azpay_product_recurrent', true); + if ($azpay_recurrent == 'yes'){ $unset = true; } } @@ -674,7 +772,8 @@ function azpay_unset_gateway_subscription( $available_gateways ) { foreach( $order->get_items() as $item_id => $item ){ //Get the WC_Product object $_product = $item->get_product(); - if ($_product->is_type('azpay_subscription')){ + $azpay_recurrent = get_post_meta($values['product_id'], 'azpay_product_recurrent', true); + if ($azpay_recurrent == 'yes'){ $unset = true; } }