I have CRITICAL Uncaught Error: Call to a member function get_meta() on null here
$Sperson = $item_val->get_meta( 'Sales Person', true );
This is preventing payments going through on the checkout page. An empty notification error is shown on the checkout page when a user clicks pay and complete order. When the below code is removed, payments go through.
The code prints the sales person to the order email
add_action('woocommerce_checkout_create_order_line_item','rw4y_add_custom_order_line_item_meta',10,4);
function rw4y_add_custom_order_line_item_meta($item, $cart_item_key, $values, $order){
if (array_key_exists('shop_manager_id', $values)) {
$custom_details = $values['shop_manager_id'];
$shop_obj = get_user_by('id', $values['shop_manager_id']);
$item->add_meta_data('SID',$values['shop_manager_id'] );
$item->add_meta_data('Sales Person',"[".$values['shop_manager_id']."] - ".$shop_obj->display_name );
$SIID = $values['shop_manager_id'];
if($SIID!='' && (get_post_meta( $order->id, 'SID', true ))=='')
{
update_post_meta( $order->id,'SID', $SIID );
$Sperson = $item_val->get_meta( 'Sales Person', true );
update_post_meta($order->id, 'Sales Person', $Sperson );
}
}
}
From Woo commerce status
2022-08-19T11:21:13+00:00 CRITICAL Uncaught Error: Call to a member function get_meta() on null in /var/www/html/wp-content/themes/roofw4u/inc/woocommerce-hooks.php:682 Stack trace: #0 /var/www/html/wp-includes/class-wp-hook.php(307): rw4y_add_custom_order_line_item_meta() #1 /var/www/html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters() #2 /var/www/html/wp-includes/plugin.php(476): WP_Hook->do_action() #3 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-checkout.php(491): do_action() #4 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-checkout.php(438): WC_Checkout->create_order_line_items() #5 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-checkout.php(381): WC_Checkout->set_data_from_cart() #6 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-checkout.php(1183): WC_Checkout->create_order() #7 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-ajax.php(461): WC_Checkout->process_checkout() #8 /var/www/html/wp-includes/class-wp-hook.php(307): WC_AJAX::checkout() in /var/www/html/wp-content/themes/roofw4u/inc/woocommerce-hooks.php on line 682