Avoid PHP notice when getting order item type
This commit changes WC_Order_Item_Data_Store::get_order_item_type() to avoid a PHP notice ("Notice: Trying to get property 'order_item_type' of non-object") when there is no entry in the database for the order item ID passed.
This commit is contained in:
parent
bccb7c3283
commit
21418bb28b
|
@ -145,11 +145,17 @@ class WC_Order_Item_Data_Store implements WC_Order_Item_Data_Store_Interface {
|
|||
*
|
||||
* @since 3.0.0
|
||||
* @param int $item_id Item ID.
|
||||
* @return string
|
||||
* @return string|null Order item type or null if no order item entry found.
|
||||
*/
|
||||
public function get_order_item_type( $item_id ) {
|
||||
global $wpdb;
|
||||
$item_data = $wpdb->get_row( $wpdb->prepare( "SELECT order_item_type FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d LIMIT 1;", $item_id ) );
|
||||
return $item_data->order_item_type;
|
||||
$order_item_type = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT order_item_type FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d LIMIT 1;",
|
||||
$item_id
|
||||
)
|
||||
);
|
||||
|
||||
return $order_item_type;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue