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); } }
public static function instance() { if (is_null(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }