You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过functions.php调整WooCommerce结算页Amazon Pay按钮位置

How to Move Amazon Pay Button/Notice on WooCommerce Checkout Page via functions.php

No need to edit the plugin files directly—you can safely adjust the position using your theme's functions.php file by unhooking the original action and rehooking it to the desired location. Here's how:

Step 1: Identify the Plugin's Callback Function

First, confirm the exact callback function the plugin uses to render the Amazon Pay button. From your note, you know it's hooked to woocommerce_before_checkout_form in woocommerce-gateway-amazon-payments-advanced.php. Open that file and look for a line like this:

add_action( 'woocommerce_before_checkout_form', array( $this, 'render_checkout_button' ) );

The second parameter (array( $this, 'render_checkout_button' ) here) is the callback you need to target. For most versions of this plugin, the callback method is render_checkout_button on the WC_Gateway_Amazon_Payments_Advanced class.

Step 2: Add This Code to Your Theme's functions.php

Paste the following code snippet into your active theme's functions.php file (or a custom plugin for safer updates):

/**
 * Relocate Amazon Pay checkout button from before to after checkout form
 */
function relocate_amazon_pay_checkout_button() {
    // Get the initialized Amazon Pay gateway instance
    $amazon_pay_gateway = WC_Gateway_Amazon_Payments_Advanced::instance();
    
    // Remove the button from its original hook
    remove_action( 'woocommerce_before_checkout_form', array( $amazon_pay_gateway, 'render_checkout_button' ) );
    
    // Re-add the button to the new checkout form hook
    add_action( 'woocommerce_after_checkout_form', array( $amazon_pay_gateway, 'render_checkout_button' ), 10 );
}
// Hook this function to run after WooCommerce initializes gateways
add_action( 'woocommerce_init', 'relocate_amazon_pay_checkout_button' );

Key Notes:

  • Priority Matching: The 10 in add_action matches the default priority used by most WooCommerce hooks. If the original plugin used a different priority, adjust this number to match.
  • Callback Name Check: If your plugin version uses a different callback method name (instead of render_checkout_button), replace it with the actual name you found in the plugin code.
  • Safety: Always back up your functions.php file before editing, or use a child theme to avoid losing changes when your parent theme updates.

内容的提问来源于stack exchange,提问作者logrexton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:13:16