user3734309
user3734309

Reputation: 41

Override Woocommerce Payment Gateway Templates

I have made a change to the eBay payment gateway file as I want to change the PayPal button text to say something else. I figured this was my best solution as I am not familiar with doing my own hooks/filters.

I have checked this amended template file works - it does. However, when I load this to my theme files it does not override.

I have tried:

  1. main theme directory
  2. theme/woocommerce/file
  3. theme/woocommerce/includes/gateways/paypal/file

None of these work... can anyone help me out?

Thanks in advance :-)

Upvotes: 1

Views: 7462

Answers (1)

iEmanuele
iEmanuele

Reputation: 1566

It seems there is no override solution to your question. But you can add a brand new payment gateway simply extending the WC_Payment_Gateway class, in other words by adding another payment gateway.

Step 1

You can duplicate the file:

plugins/woocommerce/includes/gateways/class-wc-gateway-paypal.php

in your directory theme, change its name for convenience and include it in functions.php:

/*  Custom gateway class */
require( get_template_directory() . '/path/to/class-wc-gateway-paypal-custom.php' );

Step 2

This file holds the WC_Gateway_Paypal class which extends WC_Payment_Gateway. You can edit this file for your customizations.

Remember to change the name of the extender class:

class WC_Gateway_Paypal_Custom extends WC_Payment_Gateway {
    public function __construct() {

        $this->id                = 'paypal';
        $this->icon              = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' );
        $this->has_fields        = false;
        // Change the text in the way you like it
        $this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' );
        $this->liveurl           = 'https://www.paypal.com/cgi-bin/webscr';
        $this->testurl           = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
        $this->method_title      = __( 'PayPal', 'woocommerce' );
        $this->notify_url        = WC()->api_request_url( 'WC_Gateway_Paypal' );
    }

    //other payment gateway stuff
}

Give it a try, let us know if you get stuck! : )

UPDATE 06/13/2014

It's also useful to know that there's a filter that allows you to change the paypal image, so:

function paypal_checkout_icon() {
    // pls return the new logo/image URL here
    return 'http://www.url.to/your/new/logo.png'; 
}
add_filter( 'woocommerce_paypal_icon', 'paypal_checkout_icon' );

Upvotes: 6

Related Questions