Question: Hi I need to get the product id, product variation id , and custom field text from each order. I have retrieved all except the custom field text input data, using:

```
 $product_description = get_post_meta($item['product_id'])->post_content

```

Actually crashed the site altogether whereas all other parameters work well. See snippet below:

```
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id)
{
    $order = new WC_Order( $order_id );
    $myuser_id = (int)$order->user_id;
    $user_info = get_userdata($myuser_id);
    $items = $order->get_items();
    foreach ($items as $item)
    {
        $product_name = $item['name'];
        $product_id = $item['product_id'];
        $product_variation_id = $item['variation_id'];
        $product_description = get_post_meta($item['product_id'])->post_content
    }
    return $order_id;
}

```

What might I be missing?

Answer: 
You do not need to destroy and recreate the entire Observable stream to change the `refreshInterval`. You only need to renew the part of the stream that depends on the changing interval.

First simplify your service's `getTime()` so it's not in charge of determining the frequency of outputs. All it does is return the time:

```
getTime() { return (new Date()).toString(); }

```

Now the calling code will determine the schedule. Just 3 simple steps:

**1.** A source function that adjusts to the desired interval:

```
/** Observable waits for the current interval, then emits once */
refreshObs() {return Observable.timer(this.refreshInterval)}

```

**2.** An observable chain that uses the [`repeat` operator](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/repeat.md) to continuously re-execute the stream:

```
getTime$ = Observable.of(null)
            .switchMap(e=>this.refreshObs()) // wait for interval, then emit
            .map(() => this.timeService.getTime()) // get new time
            .repeat(); // start over

```

**3.** A subscription to trigger the whole thing:

```
ngOnInit(){
    this.getTime$.subscribe(t => {
        this.currentTime = t;
        console.log('refresh interval = '+this.refreshInterval);
    });
}

```

This works because `refreshObs()` returns a new observable each time the stream is repeated, and that new observable will wait according to the currently set interval before emitting.

[**Live demo**](https://plnkr.co/edit/4eMhUXjn1t98dvRbQI56?p=preview)
I wanted to build on the previous answers here (and elsewhere on Stack Overflow). My example has a common `RefreshService` that various components can use for subscriptions. This way, a site can have a single "Refresh every X seconds" component that each component can subscribe to.

<https://plnkr.co/edit/960yztjl3dqXQD2XPSei?p=preview>

The service provides the function `withRefresh` that provides an `Observable`. It takes advantage of `BehaviorSubject`, which will immediately trigger an event on the subscription.

```
export class RefreshService {

  static interval$: BehaviorSubject<number> = new BehaviorSubject<number>(30000);

  setInterval(newInterval: number){
    RefreshService.interval$.next(newInterval);
  }

  public withRefresh() {
    return RefreshService.interval$
      .switchMap((int: number) => Observable
        .interval(int)
        .startWith(0)
      );
  }
}

```

Then any component can use this service as follows:

```
this.refreshService
  .withRefresh()
  .switchMap(() => /* do something on each interval of the timer */);

```