【发布时间】:2021-06-22 12:15:24
【问题描述】:
我想在选择特定运输方式时删除“下订单”按钮,使用优秀的LoicTheAztec“Disable “Place order” button for specific shipping method in WooCommerce”的代码,但不包括订单支付端点。
我尝试了以下解决方案,但它不起作用,Place Order 按钮也消失在 order-pay 端点上。
add_filter('woocommerce_order_button_html', 'disable_place_order_button_html' );
function disable_place_order_button_html( $button ) {
if ( is_checkout() && ! is_wc_endpoint_url( 'order-pay' ) ) {
// HERE define your targeted shipping method id
$targeted_shipping_method = "table_rate:3";
// Get the chosen shipping method (if it exist)
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
// If the targeted shipping method is selected, we disable the button
if( in_array( $targeted_shipping_method, $chosen_shipping_methods ) ) {
$style = 'style="background:Silver !important; color:white !important; cursor: not-allowed !important; text-align:center;"';
$text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
$button = '<a class="button" '.$style.'>' . $text . '</a>';
}
}
return $button;
}
感谢任何帮助。
【问题讨论】:
标签: woocommerce checkout endpoint shipping-method