我正在尝试根据送货方式隐藏结帐字段。 遵循此post
但是两种送货方式费率ID都无法显示在我的结帐页面上
function custom_checkout_field_script() {
// HERE your shipping methods rate IDs
$to_home = ['flat_rate:5', 'flat_rate:8', 'flat_rate:12', 'flat_rate:13', 'flat_rate:14', 'flat_rate:15', 'flat_rate:19', 'flat_rate:20', 'flat_rate:22'];
$to_store = ['flat_rate:6', 'flat_rate:11', 'flat_rate:16', 'flat_rate:17', 'flat_rate:18'];
$required_text = esc_attr__( 'required', 'woocommerce' );
$required_html = '<abbr class="required" title="' . $required_text . '">*</abbr>';
?>
<script>
jQuery(function($){
var ism = 'input[name^="shipping_method"]', ismc = ism+':checked',
csa = 'input#ship-to-different-address-checkbox',
rq = '-required', vr = 'validate'+rq, w = 'woocommerce', wv = w+'-validated',
iv = '-invalid', fi = '-field', wir = w+iv+' '+w+iv+rq+fi,
s = '#shipping_', f = '_field', z ='#shipping-zipcode',
a1 = 'heading_tohome', a2 = 'postcode', a3 = 'state', a4 = 'city', a5 = 'address_1',
a6 = 'heading_tostore', a7 = 'store', a8 = 'store_name', a9 = 'store_number',
s1 = s+a1+f, s2 = s+a2+f, s3 = s+a3+f, s4 = s+a4+f, s5 = s+a5+f,
s6 = s+a6+f, s7 = s+a7+f, s8 = s+a8+f, s9 = s+a9+f,
to_home = '<?php echo $to_home; ?>', to_store = '<?php echo $to_store; ?>';
// Utility function to shows or hide checkout fields
function showHide( action='show', selector='' ){
if( action == 'show' )
$(selector).show(function(){
$(this).addClass(vr);
$(this).removeClass(wv);
$(this).removeClass(wir);
if( $(selector+' > label > abbr').html() == undefined )
$(selector+' label').append('<?php echo $required_html; ?>');
});
else
$(selector).hide(function(){
$(this).removeClass(vr);
$(this).removeClass(wv);
$(this).removeClass(wir);
if( $(selector+' > label > abbr').html() != undefined )
$(selector+' label > .required').remove();
});
}
</script>
我希望当我在购物车上单击"to_home"
或"to_store"
时,它将显示正确的
结帐页面上的列,但实际情况仅显示标题,没有列