PHP Fatal error Uncaught Error: Call to a member function get_id() on null
Receiving error above in woocommerce / automatewoo.
EDIT
I'm trying to end the function if $cart_item['data']->get_id()
returns null
:
if( $value = get_post_meta( $cart_item['data']->get_id(),
'printful_variant_id', null ) ){
}
return false;
Current example below:
add_filter( 'woocommerce_get_item_data', 'display_custom_field_as_item_data', 20, 2 );
function display_custom_field_as_item_data( $cart_data, $cart_item ) {
if( $value = get_post_meta( $cart_item['data']->get_id(), 'printful_variant_id', true ) ){
$cart_data[] = array(
'name' => __( 'Var ID', 'woocommerce' ),
'value' => sanitize_text_field( $value )
);
}
return $cart_data;
}