问题描述
如果要选择包裹点取货运输方式(flat_rate:47),我正在尝试在结帐时将“附加说明”作为必填字段。如果我不使用特定的ID(47),它会起作用,并且要求在所有统一费率送货方式中填写订单说明。但我希望它只能在flat_rate:47航运上工作。到目前为止,这是我的代码,但无法正常工作。知道我在做什么错吗?
from netCDF4 import Dataset
import glob
def ncdump(nc_fid,verb=True):
'''
ncdump outputs dimensions,variables and their attribute information.
The information is similar to that of NCAR's ncdump utility.
ncdump requires a valid instance of Dataset.
Parameters
----------
nc_fid : netCDF4.Dataset
A netCDF4 dateset object
verb : Boolean
whether or not nc_attrs,nc_dims,and nc_vars are printed
Returns
-------
nc_attrs : list
A Python list of the NetCDF file global attributes
nc_dims : list
A Python list of the NetCDF file dimensions
nc_vars : list
A Python list of the NetCDF file variables
'''
def print_ncattr(key):
"""
Prints the NetCDF file attributes for a given key
Parameters
----------
key : unicode
a valid netCDF4.Dataset.variables key
"""
try:
print("\t\ttype:",repr(nc_fid.variables[key].dtype))
for ncattr in nc_fid.variables[key].ncattrs():
print('\t\t%s:' % ncattr,\
repr(nc_fid.variables[key].getncattr(ncattr)))
except KeyError:
print("\t\tWARNING: %s does not contain variable attributes" % key)
# NetCDF global attributes
nc_attrs = nc_fid.ncattrs()
if verb:
print ("NetCDF Global Attributes:")
for nc_attr in nc_attrs:
print('\t%s:' % nc_attr,repr(nc_fid.getncattr(nc_attr)))
nc_dims = [dim for dim in nc_fid.dimensions] # list of nc dimensions
# Dimension shape information.
if verb:
print("NetCDF dimension information:")
for dim in nc_dims:
print("\tName:",dim)
print("\t\tsize:",len(nc_fid.dimensions[dim]))
print_ncattr(dim)
# Variable information.
nc_vars = [var for var in nc_fid.variables] # list of nc variables
if verb:
print("NetCDF variable information:")
for var in nc_vars:
if var not in nc_dims:
print('\tName:',var)
print("\t\tdimensions:",nc_fid.variables[var].dimensions)
print("\t\tsize:",nc_fid.variables[var].size)
print_ncattr(var)
return nc_attrs,nc_vars
import sys
import os
import fileinput
ncfiles = list(glob.glob('W:/kimberley/Vectors' + '/*.nc'))
for ifile in range(len(ncfiles)):
sfile = Dataset(ncfiles[ifile],mode='r',format='NETCDF4')
base,extension = os.path.splitext(ncfiles[ifile])
output = base + '_readme.txt'
f = open(output,'w')
sys.stdout = f
ncdump(sfile)
f.close()
orig_stdout = sys.stdout
解决方法
正确的代码:
// Validate mandatory "Order notes" field for "Parcel pickup point" shipping methods
add_action( 'woocommerce_checkout_process','flat_rate_order_comment_validation',20 );
function flat_rate_order_comment_validation() {
$chosen_shipping = WC()->session->get( 'chosen_shipping_methods' )[0];
if ( $chosen_shipping == 'flat_rate:47' && empty($_POST['order_comments']) ){
wc_add_notice( __( "You need to fill up \"Order notes\" with some details.","woocommerce" ),'error' );
}
}