product_id = $product_id; } /** * offsetGet * @param string $key * @return mixed */ public function offsetGet( $key ) { return get_post_meta( $this->product_id, $this->maybe_prefix_meta_key( $key ) ); } /** * offsetSet * @param string $key * @param mixed $value */ public function offsetSet( $key, $value ) { update_post_meta( $this->product_id, $this->maybe_prefix_meta_key( $key ), $value ); } /** * offsetExists * @param string $key * @return bool */ public function offsetExists( $key ) { return metadata_exists( 'post', $this->product_id, $this->maybe_prefix_meta_key( $key ) ); } /** * Nothing to do here as we access post meta directly. */ public function offsetUnset( $key ) { } /** * We only work with post meta data that has meta keys prefixed with an underscore, so * add a prefix if it is not already set. */ protected function maybe_prefix_meta_key( $key ) { if ( '_' != substr( $key, 0, 1 ) ) { $key = '_' . $key; } return $key; } }