覆盖 Woocommerce 支付网关模板 [英] Override Woocommerce Payment Gateway Templates

查看:24
本文介绍了覆盖 Woocommerce 支付网关模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 eBay 支付网关文件进行了更改,因为我想将 PayPal 按钮文本更改为其他内容.我认为这是我最好的解决方案,因为我不熟悉自己做钩子/过滤器.

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.

我试过了:

  1. 主主题目录
  2. 主题/woocommerce/文件
  3. theme/woocommerce/includes/gateways/paypal/file

这些都不起作用……有人能帮我吗?

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

提前致谢:-)

推荐答案

您的问题似乎没有覆盖解决方案.但是你可以添加一个全新的支付网关只需扩展 WC_Payment_Gateway 类,即添加另一个支付网关.

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.

第一步

您可以复制文件:

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

在您的目录主题中,为方便起见更改其名称并将其包含在 functions.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' );

第 2 步

此文件包含扩展 WC_Payment_GatewayWC_Gateway_Paypal 类.您可以编辑此文件以进行自定义.

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! : )

更新 06/13/2014

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' );

这篇关于覆盖 Woocommerce 支付网关模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆