Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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
为收到的woocommerce电子邮件订单添加带有ACF值的占位符_Woocommerce_Advanced Custom Fields - Fatal编程技术网

为收到的woocommerce电子邮件订单添加带有ACF值的占位符

为收到的woocommerce电子邮件订单添加带有ACF值的占位符,woocommerce,advanced-custom-fields,Woocommerce,Advanced Custom Fields,我试图在WooCommerce电子邮件通知的主题中添加一个动态占位符{tipo_ordine} 我尝试了答案代码,对它做了一些小改动: add_filter( 'woocommerce_email_format_string', 'add_custom_email_format_string', 10, 2 ); function add_custom_email_format_string( $string, $email ) { // HERE the ACF slug to be

我试图在WooCommerce电子邮件通知的主题中添加一个动态占位符
{tipo_ordine}

我尝试了答案代码,对它做了一些小改动:

add_filter( 'woocommerce_email_format_string', 'add_custom_email_format_string', 10, 2 );
function add_custom_email_format_string( $string, $email ) {

    // HERE the ACF slug to be used to get the value
    $meta_key = 'tipo_ordine';

    // Get the instance of the WC_Order object
    $order   = $email->object;

    // Get ACF value (with the correct Order ID)
    $value = get_field( $meta_key, $order->get_id() );

    // Additional subject placeholder
    $new_placeholders = array( '{tipo_ordine}' => $value );

    // Get the clean replacement value string for "{tipo_ordine}" placeholder
    return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}

但它不起作用。我做错了什么?

你能在函数中加入一些var\u dump调用来检查你得到了什么实际值吗?例如,什么是$order\u id,设置在哪里?这是一个错误,我将修改$order->id!抱歉,$order->get_id()现在可以用了吗?我应该再看一眼吗?不可以,所以我通过另一个函数更改新订单电子邮件的主题,没有占位符!