function add_payment_options() { $defaults = Pay4Pay::get_default_settings(); $tax_class_options = Pay4Pay::instance()->get_woocommerce_tax_classes(); // general $form_fields = array('pay4pay_title' => array('title' => __('Extra Charge', 'woocommerce-payforpayment'), 'type' => 'title', 'class' => 'pay4pay-title', 'description' => ''), 'pay4pay_item_title' => array('title' => __('Item Title', 'woocommerce-payforpayment'), 'type' => 'text', 'description' => __('This will show up in the shopping basket.', 'woocommerce-payforpayment'), 'desc_tip' => true), 'pay4pay_charges_fixed' => array('title' => __('Fixed charge', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Extra charge to be added to cart when this payment method is selected.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any')), 'pay4pay_charges_percentage' => array('title' => __('Percent charge', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Percentage of cart total to be added to payment.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any', 'data-setchangehandler' => '1', 'data-reference-name' => 'woocommerce-pay4pay-percentage'), 'id' => 'woocommerce-pay4pay-percentage'), 'pay4pay_charges_minimum' => array('title' => __('Charge at least', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Minimum extra charge to be added to cart when this payment method is selected.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any', 'data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_charges_maximum' => array('title' => __('Charge at most', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Maximum extra charge to be added to cart when this payment method is selected. Enter zero to disable.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any', 'data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_disable_on_free_shipping' => array('title' => __('Disable on Free Shipping', 'woocommerce-payforpayment'), 'label' => __('Don’t charge this fee when free shipping is available.', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'desc_tip' => true)); // taxes if ('yes' == get_option('woocommerce_calc_taxes')) { $form_fields += array('pay4pay_title_taxes' => array('title' => __('Extra Charge Taxes', 'woocommerce-payforpayment'), 'type' => 'title', 'class' => 'pay4pay-title'), 'pay4pay_taxes' => array('title' => __('Taxable', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Payment fee is taxable', 'woocommerce-payforpayment'), 'custom_attributes' => array('data-setchangehandler' => '1', 'data-reference-name' => 'woocommerce-pay4pay-taxes')), 'pay4pay_includes_taxes' => array('title' => __('Inclusive Taxes', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('The payment fee is inclusive of taxes.', 'woocommerce-payforpayment'), 'description' => __('If you leave this unchecked taxes will be calculated on top of the payment fee.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_taxes', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-taxes')), 'pay4pay_tax_class' => array('title' => __('Tax class', 'woocommerce-payforpayment'), 'type' => 'select', 'description' => __('Select a the tax class applied to the extra charge.', 'woocommerce-payforpayment'), 'options' => $tax_class_options, 'desc_tip' => true, 'class' => 'pay4pay_taxes', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-taxes'))); } // include in calculation $form_fields += array('pay4pay_title_include' => array('title' => __('Include in percental payment fee calculation:', 'woocommerce-payforpayment'), 'type' => 'title', 'class' => 'pay4pay-title dependency-notzero-woocommerce-pay4pay-percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_enable_extra_fees' => array('title' => __('Fees', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include fees in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_include_coupons' => array('title' => __('Coupons', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include Coupons in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_include_shipping' => array('title' => __('Shipping', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include shipping cost in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage'))); if ('yes' == get_option('woocommerce_calc_taxes')) { $form_fields += array('pay4pay_include_cart_taxes' => array('title' => __('Taxes', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include taxes in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage'))); } foreach ($defaults as $option_key => $default_value) { if (array_key_exists($option_key, $form_fields)) { $form_fields[$option_key]['default'] = $default_value; } } foreach (WC()->payment_gateways()->payment_gateways() as $gateway_id => $gateway) { $form_fields['pay4pay_item_title']['default'] = $gateway->title; $gateway->form_fields += $form_fields; add_action('woocommerce_update_options_payment_gateways_' . $gateway->id, array($this, 'update_payment_options'), 20); } }
} else { return false; } } function get_current_gateway_settings() { if ($current_gateway = $this->get_current_gateway()) { $defaults = self::get_default_settings(); $settings = $current_gateway->settings + $defaults; return $settings; } return false; } public function get_woocommerce_tax_classes() { // I can't belive it really works like this! $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes')))); $tax_class_options = array(); $tax_class_options[''] = __('Standard', 'woocommerce'); if ($tax_classes) { foreach ($tax_classes as $class) { $tax_class_options[sanitize_title($class)] = esc_attr($class); } } return $tax_class_options; } } Pay4Pay::instance(); if (is_admin()) { require_once plugin_dir_path(__FILE__) . '/admin/class-pay4pay-admin.php'; }