I've created a custom user role and am attempting to change the users role from CUSTOMER to ADVOCATE on purchase of a particular product (using WooCommerce). I'm really close but struggling to get the correctly serialized data into my table:
$order = new WC_Order( $order_id );
$items = $order->get_items();
$new_role = 'Array([advocate] => 1)';
$data = serialize( $new_role );
if ( $product_id == '786' ) {
update_user_meta( $order->user_id, 'wp_capabilities', $data );
}
The correct table is being populated at the correct time but as
s:30:"s:22:"Array([advocate] => 1)";";
rather than what I need it to be which is
a:1:{s:8:"advocate";b:1;}
Where is my serialization tripping up?