id = 'bkash'; $this->icon = apply_filters('woocommerce_dbblmb_icon', plugins_url( '/images/bKash.png', __FILE__ )); $this->has_fields = false; $this->method_title = __( 'bkash', 'woocommerce' ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->instructions = $this->get_option( 'instructions', $this->description ); $this->enable_for_methods = $this->get_option( 'enable_for_methods', array() ); $this->enable_for_virtual = $this->get_option( 'enable_for_virtual', 'yes' ) === 'yes' ? true : false; // bKash account fields shown on the thanks page and in emails $this->account_details = get_option( 'woocommerce_bkash_accounts', array( array( 'account_type' => $this->get_option( 'account_type' ), 'account_number' => $this->get_option( 'account_number' ) ) ) ); // Actions add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) ); add_action( 'woocommerce_thankyou_bkash', array( $this, 'thankyou_page' ) ); // Customer Emails add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); } /** * Initialise Gateway Settings Form Fields */ public function init_form_fields() { $shipping_methods = array(); if ( is_admin() ) foreach ( WC()->shipping()->load_shipping_methods() as $method ) { $shipping_methods[ $method->id ] = $method->get_title(); } $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable bKash Mobile Banking', 'woocommerce' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'woocommerce' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'default' => __( 'bKash Mobile Banking', 'woocommerce' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'woocommerce' ), 'type' => 'textarea', 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ), 'default' => __( 'Description', 'woocommerce' ), 'desc_tip' => true, ), 'instructions' => array( 'title' => __( 'Instructions', 'woocommerce' ), 'type' => 'textarea', 'description' => __( 'Instructions', 'woocommerce' ), 'default' => 'Instructions', 'desc_tip' => true, ), 'enable_for_methods' => array( 'title' => __( 'Enable for shipping methods', 'woocommerce' ), 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'css' => 'width: 450px;', 'default' => '', 'description' => __( 'If bKash is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'woocommerce' ), 'options' => $shipping_methods, 'desc_tip' => true, 'custom_attributes' => array( 'data-placeholder' => __( 'Select shipping methods', 'woocommerce' ) ) ), 'enable_for_virtual' => array( 'title' => __( 'Enable for virtual orders', 'woocommerce' ), 'label' => __( 'Enable bKash if the order is virtual', 'woocommerce' ), 'type' => 'checkbox', 'default' => 'yes' ), 'account_details' => array( 'type' => 'account_details' ) ); } /** * Check If The Gateway Is Available For Use * * @return bool */ public function is_available() { $order = null; if ( ! $this->enable_for_virtual ) { if ( WC()->cart && ! WC()->cart->needs_shipping() ) { return false; } if ( is_page( wc_get_page_id( 'checkout' ) ) && 0 < get_query_var( 'order-pay' ) ) { $order_id = absint( get_query_var( 'order-pay' ) ); $order = wc_get_order( $order_id ); // Test if order needs shipping. $needs_shipping = false; if ( 0 < sizeof( $order->get_items() ) ) { foreach ( $order->get_items() as $item ) { $_product = $order->get_product_from_item( $item ); if ( $_product->needs_shipping() ) { $needs_shipping = true; break; } } } $needs_shipping = apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping ); if ( $needs_shipping ) { return false; } } } if ( ! empty( $this->enable_for_methods ) ) { // Only apply if all packages are being shipped via local pickup $chosen_shipping_methods_session = WC()->session->get( 'chosen_shipping_methods' ); if ( isset( $chosen_shipping_methods_session ) ) { $chosen_shipping_methods = array_unique( $chosen_shipping_methods_session ); } else { $chosen_shipping_methods = array(); } $check_method = false; if ( is_object( $order ) ) { if ( $order->shipping_method ) { $check_method = $order->shipping_method; } } elseif ( empty( $chosen_shipping_methods ) || sizeof( $chosen_shipping_methods ) > 1 ) { $check_method = false; } elseif ( sizeof( $chosen_shipping_methods ) == 1 ) { $check_method = $chosen_shipping_methods[0]; } if ( ! $check_method ) { return false; } $found = false; foreach ( $this->enable_for_methods as $method_id ) { if ( strpos( $check_method, $method_id ) === 0 ) { $found = true; break; } } if ( ! $found ) { return false; } } return parent::is_available(); } /** * generate_account_details_html function. */ public function generate_account_details_html() { ob_start(); ?>