Php 正在尝试在woocommerce的签出页面中的total部分后放置自定义字段
这段代码可以正常工作,但不会将自定义字段放置在我想要的位置。在add_操作中,我想使用woocommerce_review_order_after_order_total作为location属性将其放置在页面上。我从这本视觉指南中获得了钩子名称,但是这个钩子(在下面代码中的注释中看到)破坏了我的代码,并给出了以下php错误Php 正在尝试在woocommerce的签出页面中的total部分后放置自定义字段,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,这段代码可以正常工作,但不会将自定义字段放置在我想要的位置。在add_操作中,我想使用woocommerce_review_order_after_order_total作为location属性将其放置在页面上。我从这本视觉指南中获得了钩子名称,但是这个钩子(在下面代码中的注释中看到)破坏了我的代码,并给出了以下php错误 Fatal error: Uncaught Error: Call to a member function get_value() on string in /Users/
Fatal error: Uncaught Error: Call to a member function get_value() on string in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/themes/salient-child/functions.php on line 96
希望有人能帮我。谢谢
/**
* Add custom field to the checkout page
*/
add_action('woocommerce_after_order_notes', 'custom_checkout_field');
/* add_action('woocommerce_review_order_after_order_total', 'custom_checkout_field');*/
/* ^ This is the code that is breaking */
function custom_checkout_field($checkout)
{
echo '<div id="custom_checkout_field"><h2>' . __('New Heading') . '</h2>';
woocommerce_form_field(
'custom_field_name',
array(
'type' => 'text',
'class' => array(
'my-field-class form-row-wide'
) ,
'label' => __('Custom Additional Field') ,
'placeholder' => __('New Custom Field') ,
) ,
$checkout->get_value('custom_field_name')
);
echo '</div>';
}
/**
*将自定义字段添加到签出页面
*/
添加操作(“订单注释后的woocommerce”、“自定义签出字段”);
/*添加操作('WOOMerce\u review\u order\u after\u order\u total','custom\u checkout\u field')*/
/*^这是正在中断的代码*/
函数自定义检查字段($checkout)
{
回显“.”(“新标题”);
woocommerce\u form\u字段(
“自定义字段名称”,
排列(
'类型'=>'文本',
“类”=>数组(
“我的字段类表格行宽”
) ,
“label'=>”(自定义附加字段),
“占位符”=>“(“新自定义字段”),
) ,
$checkout->get\u value('自定义\u字段\u名称')
);
回声';
}
删除$checkout->get\u value('custom\u field\u name')
,这样就可以:
woocommerce_form_field(
'custom_field_name',
array(
'type' => 'text',
'class' => array(
'my-field-class form-row-wide'
) ,
'label' => __('Custom Additional Field') ,
'placeholder' => __('New Custom Field') ,
)
);
任何用户值都应自动填充,否则将为空