禁用WooCommerce中特定运输方式的“下订单"按钮 [英] Disable “Place order” button for specific shipping method in WooCommerce

查看:40
本文介绍了禁用WooCommerce中特定运输方式的“下订单"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选择特定的送货方式后,我想禁用下订单"按钮,有点像"

要使其适用于特定的送货方式ID,您将使用以下内容:

  add_filter('woocommerce_order_button_html','disable_place_order_button_html');函数disable_place_order_button_html($ button){//在此定义您的目标送货方式ID$ targeted_shipping_method ="flat_rate:14";//获取所选的送货方式(如果存在)$ chosen_shipping_methods = WC()-> session-> get('chosen_shipping_methods');//如果选择了目标送货方式,我们将禁用该按钮if(in_array($ targeted_shipping_method,$ chosen_shipping_methods)){$ style ='style ='''background:Silver!important;颜色:白色!重要;光标:不允许!重要;text-align:center;;'$ text = apply_filters('woocommerce_order_button_text',__('下订单','woocommerce'));$ button ='< a class ="button"'.$ style.'>'.$ text.'</a>';}返回$ button;} 

代码进入活动子主题(或活动主题)的functions.php文件中.经过测试并可以正常工作.

I would like to disable the "Place order" button when a specific shipping method is selected, a bit like in "Disable "Place order" button for specific shipping zone in WooCommerce" answer to my previous question, but for a specific Shipping Method instead of a Shipping Zone.

The name of the related shipping method is "LATAM".

Any help is appreciated.

解决方案

First you need to inspect the shipping methods radio buttons, to find out the shipping method ID corresponding value to "LATAM"…

To make it work for a specific shipping method ID you will use the following:

add_filter('woocommerce_order_button_html', 'disable_place_order_button_html' );
function disable_place_order_button_html( $button ) {
    // HERE define your targeted shipping method id
    $targeted_shipping_method = "flat_rate:14";

    // 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;
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

这篇关于禁用WooCommerce中特定运输方式的“下订单"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆