Php WooCommerce ACF在购物车和结账页面上显示自定义元数据

Php WooCommerce ACF在购物车和结账页面上显示自定义元数据,php,wordpress,woocommerce,advanced-custom-fields,product,Php,Wordpress,Woocommerce,Advanced Custom Fields,Product,我想在WooCommerce购物车和结帐页面中同时显示使用插件创建的自定义字段的值 我在主题的functions.php页面中使用以下代码,该页面仅显示在产品的单个页面中: add_action( 'woocommerce_before_add_to_cart_button', 'add_custom_field', 0 ); function add_custom_field() { global $post; echo "<div class='produto-info

我想在WooCommerce购物车和结帐页面中同时显示使用插件创建的自定义字段的值

我在主题的
functions.php
页面中使用以下代码,该页面仅显示在产品的单个页面中:

add_action( 'woocommerce_before_add_to_cart_button', 'add_custom_field', 0 );

function add_custom_field() {
    global $post;

  echo "<div class='produto-informacoes-complementares'>";
  echo get_field( 'info_complementar', $product_id, true );
  echo "</div>";

    return true;
}
add_操作('woocommerce_之前的'add_to_cart_按钮','add_custom_字段',0);
函数添加\自定义\字段(){
全球$员额;
回声“;
echo get_字段('info_complementar',$product_id,true);
回声“;
返回true;
}

感谢所有高级人员提供的帮助并原谅我的英语。

我无法在您的网上商店测试这一点,因此我不能完全确定:

在单个产品页面中显示自定义字段值(您的函数):

(更新)在购物车和结帐时呈现元:

add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 );

function render_meta_on_cart_and_checkout( $cart_data, $cart_item ) {
    $custom_items = array();
    // Woo 2.4.2 updates
    if( !empty( $cart_data ) ) {
        $custom_items = $cart_data;
    }
    if( isset( $cart_item['info_complementar'] ) ) {
        $custom_items[] = array( "name" => "Info complementar", "value" => $cart_item['info_complementar'] );
    }
    return $custom_items;
}

最后两个钩子中出现了一些错误,使其无法工作……现在应该可以工作了。

我无法在您的网上商店中测试此功能,因此我不能完全确定:

在单个产品页面中显示自定义字段值(您的函数):

(更新)在购物车和结帐时呈现元:

add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 );

function render_meta_on_cart_and_checkout( $cart_data, $cart_item ) {
    $custom_items = array();
    // Woo 2.4.2 updates
    if( !empty( $cart_data ) ) {
        $custom_items = $cart_data;
    }
    if( isset( $cart_item['info_complementar'] ) ) {
        $custom_items[] = array( "name" => "Info complementar", "value" => $cart_item['info_complementar'] );
    }
    return $custom_items;
}

最后两个钩子中出现了一些错误,使其无法工作……现在应该可以工作了。

Loic这是一个旧钩子名称吗?@Wed使用的钩子仍在上一个Woocommerce版本上工作。Loic这是一个旧钩子名称吗?@Wed使用的钩子仍在上一个Woocommerce版本上工作。
add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 );

function render_meta_on_cart_and_checkout( $cart_data, $cart_item ) {
    $custom_items = array();
    // Woo 2.4.2 updates
    if( !empty( $cart_data ) ) {
        $custom_items = $cart_data;
    }
    if( isset( $cart_item['info_complementar'] ) ) {
        $custom_items[] = array( "name" => "Info complementar", "value" => $cart_item['info_complementar'] );
    }
    return $custom_items;
}