I have added a custom column to WooCommerce Products page in Admin Dashboard, however when trying to populate column with adding 2 custom ACF fields setup for Post Type -> Products, I am receiving error notice on debug listed on every product in that custom column.
Notice: Undefined variable: product in /./././wp-content/themes/bpa/functions.php on line 923
Notice: Trying to get product 'id' of non-object in /./././wp-content/themes/bpa/functions.php on line 923
Could anyone please help explain what I'm doing wrong to get undefined variable?
Line 923 is :
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
Is it because I'm using an old approach for WC or something?
Full Function:
// Populate column
function woo_product_rmreference_column_data( $column ) {
global $post;
if ( $column == 'rm_reference' ) {
//
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
// Get ACF Fields
$reference = get_field( 'property_reference', $product_id );
$address = get_field( 'location', $product_id );
// Output
echo ($reference . $address) ? '<div>'.$reference.' - '.$address.'</div>' : '<div>Not found!</div>';
}
}
add_action( 'manage_product_posts_custom_column' , 'woo_product_rmreference_column_data', 10, 2 );