【发布时间】:2022-01-26 01:43:39
【问题描述】:
我隐藏了billing_email 字段,并为此字段设置了一个默认值,即特定的电子邮件地址。
我在functions.php中插入的代码如下:
add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
function default_values_checkout_fields( $fields ) {
// You can use this for postcode, address, company, first name, last name and such.
$fields['billing']['billing_email']['placeholder'] = 'mymail@hotmail.hr';
$fields['billing']['billing_email']['autocomplete'] = 'mymail@hotmail.fr';
$fields['billing']['billing_email']['default'] = 'mymail@hotmail.fr';
return $fields;
}
我实际上希望根据所购买的产品将不同的电子邮件设置为默认电子邮件。 (已经购物车只允许一种产品)。
这些值可以用如下sn-p如下所示的条件设置吗?
add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
function default_values_checkout_fields( $fields ) {
// You can use this for postcode, address, company, first name, last name and such.
if $product_id === 17 {
$fields['billing']['billing_email']['placeholder'] = 'mymail@hotmail.hr';
$fields['billing']['billing_email']['autocomplete'] = 'mymail@hotmail.fr';
$fields['billing']['billing_email']['default'] = 'mymail@hotmail.fr';
return $fields;
}}
【问题讨论】:
-
嗯,我的回答好像没有得到任何反馈?
标签: wordpress woocommerce product cart hook-woocommerce