Search code examples
wordpresswoocommercepayment-gatewayhook-woocommercewordpress-plugin-creation

How to use file upload option in WooCommerce payment gateway admin options?


I am developing a plugin to integrate a payment gateway in WooCommerce. I have done one before.

But in this one, I need to upload a key file in gateway settings and that is used to hash the data before making payment request to related portal.

I have following code which allows to choose file, but I doubt this is working in the back end.

    'sandbox_pvt_key' => array(
        'title'       => __( 'Test Private Key', 'woocommerce-custom-gateway' ),
        'type'        => 'file',
        'desc_tip'    => true,
        'description' => __( 'Please upload the test private key file; this is needed in order to test payment.', 'woocommerce-custom-gateway' ),
        'default'     => '',
    ),

The output looks like the following: enter image description here

Can anybody lemme know if this is supported option in the gateway settings? If not, can anybody guide me on how I can customize it via some hook/filters or any other way.


Solution

  • This can be achieved in the process_admin_options()

    public function process_admin_options() {
       $this->upload_key_files();
    
       $saved = parent::process_admin_options();
    
       return $saved;
    }
    
    private function upload_key_files() {
        //handle uploads here
    }