Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何添加使用acf为用户帐户创建的自定义字段,以便在woocommerce的签出表单中显示_Woocommerce_Advanced Custom Fields - Fatal编程技术网

如何添加使用acf为用户帐户创建的自定义字段,以便在woocommerce的签出表单中显示

如何添加使用acf为用户帐户创建的自定义字段,以便在woocommerce的签出表单中显示,woocommerce,advanced-custom-fields,Woocommerce,Advanced Custom Fields,我已经在用户帐户中使用ACF创建了一个自定义字段,该字段显示有关付款方式的消息。我无法使其显示在结帐页面中 我已经将这段代码添加到checkout-form.php中,但不起作用,它只显示“empty”。“付款方法消息”是ACF中的字段名 <?php $value = get_field( "payment_method_message", $user ); echo $value; ?> 我想在finish order按钮之前显示此字段。提前谢谢你 注: 我也试着在fun

我已经在用户帐户中使用ACF创建了一个自定义字段,该字段显示有关付款方式的消息。我无法使其显示在结帐页面中

我已经将这段代码添加到checkout-form.php中,但不起作用,它只显示“empty”。“付款方法消息”是ACF中的字段名

<?php $value = get_field( "payment_method_message", $user );

echo $value;

?>

我想在finish order按钮之前显示此字段。提前谢谢你

注:
我也试着在function.php中添加这个,但没有再次添加任何内容

    add_action('woocommerce_after_order_note','display_acf_field_on_checkout'); 

    function display_acf_field_on_checkout()

    { echo '<b>Payment method message:</b>' . 
    get_field('payment_method_message',$user_id); 
    // Note: 'payment_method_message' is the slug of the ACF }
add_action('u order_note'后面的woocommerce_,'display_acf_field_on_checkout');
功能显示\u acf\u字段\u在\u签出()上
{echo'付款方式消息:'。
获取字段('payment\u method\u message',$user\u id);
//注意:'payment_method_message'是ACF}的slug
解决方法:我用下面的代码计算出来,我把它放在childtheme目录下的payment.php模板中。它工作得很好

<?php 

$value = get_field('payment_method_message',  
'user_'.get_current_user_id());

if( $value = get_field( 'payment_method_message',  
'user_'.get_current_user_id() ) ) { echo "<h3 style='margin:0;font- 
weight: 600;'>" . 'Payment Method: '  .  $value . '</h3>' ; }

?>


如何定义
$user
变量?我认为问题就出在这里……你应该尝试使用
if($value=get\u字段(“payment\u method\u message”,get\u current\u user\u id()){echo value;}
我做了这个更改,但仍然没有任何结果。。。我才刚刚开始,所以我不知道我做错了什么。。。。我还尝试在function.php中添加这个,但没有再次添加任何内容…
add\u操作('woocommerce\u在'u order\u note'之后,'display\u acf\u field\u on\u checkout');函数display_acf_field_on_checkout(){echo'Payment method message:'.get_field('Payment_method_message',$user_id);//注意:'Payment_method_message'是acf的slug}
acf在某些情况下是反复无常的,取决于您的设置……所以我不能给您任何其他信息。您如何定义
$user
变量?我认为问题就出在这里……你应该尝试使用
if($value=get\u字段(“payment\u method\u message”,get\u current\u user\u id()){echo value;}
我做了这个更改,但仍然没有任何结果。。。我才刚刚开始,所以我不知道我做错了什么。。。。我还尝试在function.php中添加这个,但没有再次添加任何内容…
add\u操作('woocommerce\u在'u order\u note'之后,'display\u acf\u field\u on\u checkout');函数display_acf_field_on_checkout(){echo'Payment method message:'。get_field('Payment_method_message',$user_id);//注意:'Payment_method_message'是acf的slug}
acf在某些情况下是反复无常的,取决于您的设置……因此我不能给您任何其他信息。