首页 > 解决方案 > 将 ACF 字段添加到 WooCommerce 订单列表列

问题描述

我已经尝试过这段代码,它添加了列并添加数据仅显示“确认未更新”我想显示此元数据“acknowledge_noo”,这是“acknowledge_noo”ACF 字段

add_filter( 'yith_wcfm_print_shortcode_template_args', 'yith_wcfm_print_shortcode_template_args', 20 );
if ( ! function_exists( 'yith_wcfm_print_shortcode_template_args' ) ) {
function yith_wcfm_print_shortcode_template_args( $cols ) {
$columns = $cols['columns'];
    $keys            = array_keys( $columns );  
    $first           = array_slice( $columns, 0, $ship_to_pos );
    $last            = array_slice( $columns, $ship_to_pos + 1 );
$billing_to_col = array( 'acknowledge' => __( 'Acknowledge', 'yith-frontend-manager-for-woocommerce') );
$cols['columns'] = array_merge( $first,$billing_to_col, $last );
    return $cols;
}
}
add_action( 'yith_wcfm_order_cols', 'yith_wcfm_order_biloing_to_coll', 10, 2 );
if ( ! function_exists( 'yith_wcfm_order_biloing_to_coll' ) ) {
function yith_wcfm_order_biloing_to_coll( $column, $post) {
    if ( 'acknowledge' == $column ) {
        global $post;
    if ( $address = $order = wc_get_order( $post->ID ) ) {  
     $address = wc_get_order_item_meta( $item_id, 'acknowledge_noo', true );
        $tooltip = __('Print details', 'textdomain');
        echo '<a href="/wp-content/uploads/customerpdf/'.$address.'.pdf" data-tip="'.$tooltip.'" target="_blank">'.$address.'</a>';
        } 
        else {
            echo 'Acknowledge Not Updated';
        }           
    }       
}
}

标签: phpwordpresswoocommerceadvanced-custom-fields

解决方案


推荐阅读