【问题标题】:Modify "Proceed to checkout" button without shipping method in WooCommerce在 WooCommerce 中修改“继续结帐”按钮而不使用送货方式
【发布时间】:2021-06-23 13:32:14
【问题描述】:

我想使用代码“Prevent access to checkout without shipping method in WooCommerce”和“Avoid proceed-to-checkout-button text refreshing to default text in WooCommerce cart page”更改“继续结帐”按钮的文本而不使用送货方式。

这是我失败的尝试:

function modify_checkout_button_no_shipping() {
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );    
if( empty( $chosen_shipping_methods ) ) {
    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
    add_action( 'woocommerce_proceed_to_checkout', 'modify_checkout_button_no_shipping', 20 );
    echo '<a href="'.esc_url(wc_get_checkout_url()).'" class="checkout-button button alt wc-forward">' . __("Alternate checkout text", "woocommerce") . '</a>';
}
}

感谢任何帮助。

【问题讨论】:

    标签: php woocommerce cart shipping-method


    【解决方案1】:

    add_action 必须插入到modify_checkout_button_no_shipping 函数之外。

    否则你的代码可以正常工作。

    试试这个:

    add_action( 'woocommerce_proceed_to_checkout', 'modify_checkout_button_no_shipping', 1 );
    function modify_checkout_button_no_shipping() {
        $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
        // removes empty values from the array
        $chosen_shipping_methods = array_filter( $chosen_shipping_methods );
        if ( empty( $chosen_shipping_methods ) ) {
            remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
            echo '<a href="'.esc_url(wc_get_checkout_url()).'" class="checkout-button button alt wc-forward">' . __("Alternate checkout text", "woocommerce") . '</a>';
        }
    }
    

    代码已经过测试并且可以运行。将其添加到活动主题的 functions.php 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多