根据运输选项更改结帐表单 - 商业



您如何更改不同运输选项的woo-commerce结帐表单?如果他们选择免费送货,结帐页面将显示送货表格。如果他们选择电子凭证,结帐页面将显示一个更简单的表单。

您可以使用以下代码片段隐藏您在选择"电子凭证"运输方式时选择的任何字段。只需将以下内容放入函数文件中即可。

<?php
add_filter('woocommerce_checkout_fields', 'evoucher_remove_fields');
function evoucher_remove_fields($fields) {
$shipping_method ='evoucher:1'; // Change this to the value name of your shipping method
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping == $shipping_method) {
unset($fields['billing']['billing_address_1']); // Hides billing address line 1
unset($fields['billing']['billing_address_2']); // Hides billing address line 2
}
return $fields;
}
?>

有一个很好的插件用于此类目的。它的免费版本包括条件逻辑,例如使用基于运输选项更改表单。

最新更新