我正在使用WooCommerce,并在“结帐”页面上启用了“运送到其他地址”部分。我想将其保留在那里,但是我试图删除几个字段。更具体地说,我尝试删除名字,姓氏和州/省字段。我在子主题的functions.php文件中添加了以下代码:
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_state']);
unset($fields[‘shipping’][‘shipping_first_name’]);
unset($fields[‘shipping’][‘shipping_last_name’]);
unset($fields[‘shipping’][‘shipping_state’]);
return $fields;
}
当我使用此代码时,帐单字段会消失,但是当我打开“运送到其他地址”时,所有运送字段都会保留。不完全确定我在这里做错什么,任何帮助将不胜感激。感谢您的宝贵时间。
答案 0 :(得分:0)
请检查,下面的代码中有语法错误。因为我认为WordPress不接受数组中的引号。
Option Explicit
Public Sub Loop_Example()
Dim Firstrow As Long, Lastrow As Long, Lrow As Long, CalcMode As Long, ViewMode As Long, Columnname As String
Dim DeleteStr As String, unionRng As Range, rng As Range
Columnname = Application.InputBox("Select Column", , Type:=2)
DeleteStr = Application.InputBox("Delete Text", , Type:=2)
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Activate
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .Cells(.Rows.Count, Columnname).End(xlUp).Row
Dim loopRange As Range: Set loopRange = .Range("C" & Firstrow & ":" & "C" & Lastrow)
For Each rng In loopRange
If rng.Value = DeleteStr Then
If Not unionRng Is Nothing Then
Set unionRng = Union(unionRng, rng)
Else
Set unionRng = rng
End If
End If
Next
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
If Not unionRng Is Nothing Then unionRng.EntireRow.Delete
End Sub
请使用单引号,请使用下面的代码,然后进行测试
unset($fields[‘shipping’][‘shipping_first_name’]);
unset($fields[‘shipping’][‘shipping_last_name’]);
unset($fields[‘shipping’][‘shipping_state’]);