【问题标题】:How to change woocommerce checkout button for payment gateway? [duplicate]如何更改支付网关的 woocommerce 结帐按钮? [复制]
【发布时间】:2020-06-30 04:39:13
【问题描述】:

我正在尝试创建一个基于 javascript API 的自定义支付网关。结帐时的按钮必须像贝宝结帐按钮一样工作,这会打开另一个窗口,但我找不到替换按钮的方法。由于按钮是由javascript加载的,而html只是一个地方

add_filter( 'woocommerce_order_button_html', 'custom_order_button_html');
function custom_order_button_html( $button ) {

    // The text of the button
    $order_button_text = __(' order', 'woocommerce');

    // HERE you make changes (Replacing the code of the button):
    $button = '<div id="custom_Checkout_Button"></div>'; 
}

我把这个函数放在function __construct 中,但它不会替换。

脚本正在正确加载。如果我通过控制台加载脚本,它的加载很好。

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    所以我所做的是在此处链接的更改方法

    Change Pay button on checkout based on Woocommerce chosen payment method

    并使用另一个 jquery 调用来重新加载我需要的脚本,它就像一个魅力。

    如果有正确/更好的方法可以将其作为答案,我会接受。

    【讨论】:

      【解决方案2】:

      当您使用add_filter 时,您总是需要返回您想要过滤或修改的内容。因此,在您的情况下,代码如下所示。

      add_filter( 'woocommerce_order_button_html', 'custom_order_button_html');
      function custom_order_button_html( $button ) {
      
          // The text of the button
          $order_button_text = __(' order', 'woocommerce');
      
          // HERE you make changes (Replacing the code of the button):
          $button = '<div id="custom_Checkout_Button"></div>';
      
          // Return the modified/filtered content
          return $button;
      }
      

      您可以找到更多使用示例here

      【讨论】:

      • 好的,这是问题之一,所以现在它会显示,但会闪烁并消失。我在构造函数中做这个过滤器,然后调用脚本的入队。
      • 所以,我让它像我说的那样工作,但是考虑到我的问题,你有正确的答案。谢谢。
      猜你喜欢
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 2012-12-28
      • 2019-06-15
      • 2019-12-28
      • 2018-08-30
      相关资源
      最近更新 更多