我正在建立一个WooCommerce电子商店,我需要通过执行以下操作来调整我的结帐页面:
如果订单总额>隐藏某种送货方式(仅限一种) 100€。
如果选择了本地取件,则隐藏货到付款方式。
有谁知道怎么做?我有Code Snippets插件,所以我可以轻松添加任何自定义代码。
谢谢!
答案 0 :(得分:2)
要隐藏基于购物车总额的特定送货方式,您可以使用以下代码段。您需要在代码中更新送货方式名称。
根据购物车总数停用送货方式
在主题的functions.php
文件或自定义插件文件中添加此代码段。
add_filter( 'woocommerce_package_rates', 'shipping_based_on_price', 10, 2 );
function shipping_based_on_price( $rates, $package ) {
$total = WC()->cart->cart_contents_total;
//echo $total;
if ( $total > 100 ) {
unset( $rates['local_delivery'] ); // Unset your shipping method
}
return $rates;
}
停用特定送货方式的付款网关
使用下面的代码段。根据您的付款方式更新代码&运输方式。
add_filter( 'woocommerce_available_payment_gateways', 'x34fg_gateway_disable_shipping' );
function x34fg_gateway_disable_shipping( $available_gateways ) {
global $woocommerce;
if ( !is_admin() ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
unset( $available_gateways['cod'] );
}
}
return $available_gateways;
}
答案 1 :(得分:1)
这些方面的东西:
function alter_payment_gateways( $gateways ){
$chosen_rates = ( isset( WC()->session ) ) ? WC()->session->get( 'chosen_shipping_methods' ) : array();
if( in_array( 'local-pickup:6', $chosen_rates ) ) {
$array_diff = array('cod');
$list = array_diff( $list, $array_diff );
}
return $list;
}
add_action('woocommerce_payment_gateways', 'alter_payment_gateways', 50, 1);
第4行“本地取件”结束时的数字取决于您的woocommerce设置。您可以通过向购物篮添加内容,进入结帐,右键单击交付方法中的“本地提货”选项并查看值属性来找到您需要放入的字符串。