tring The meta description. */ public function metadesc( $metadesc ) { if ( '' !== $metadesc || ! is_singular( 'product' ) ) { return $metadesc; } $product = $this->get_product_by_id( get_the_id() ); if ( ! is_object( $product ) ) { return ''; } $short_desc = $this->get_short_description( $product ); if ( '' !== $short_desc ) { return $short_desc; } $long_desc = $this->get_long_description( $product ); return '' !== $long_desc ? Str::truncate( $long_desc, 156 ) : ''; } /** * Returns the product for given product_id. * * @param int $product_id The id to get the product for. * * @return null|WC_Product */ protected function get_product_by_id( $product_id ) { if ( function_exists( 'wc_get_product' ) ) { return wc_get_product( $product_id ); } if ( function_exists( 'get_product' ) ) { return get_product( $product_id ); } return null; } /** * Checks if product class has a description method. * Otherwise it returns the value of the post_content. * * @param WC_Product $product The product. * * @return string */ protected function get_long_description( $product ) { if ( method_exists( $product, 'get_description' ) ) { return $product->get_description(); } return $product->post->post_content; } }