在 WooCommerce 中修改没有送货方式的 "Proceed to checkout" 按钮
Modify "Proceed to checkout" button without shipping method in WooCommerce
我想使用代码“" and "”更改没有送货方式的“继续结帐”按钮的文本。
这是我失败的尝试:
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>';
}
}
感谢任何帮助。
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.
我想使用代码“
这是我失败的尝试:
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>';
}
}
感谢任何帮助。
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.