filters( 'premmerce_permalink_manager_canonical', $this->getCanonical() ); if ( !empty($canonical) ) { echo '' . "\n" ; } } } private function getCanonical( $useCommentsPagination = false ) { global $wp_rewrite ; $qo = get_queried_object(); $canonical = null; if ( $qo instanceof WP_Term ) { $canonical = get_term_link( $qo ); $paged = get_query_var( 'paged' ); if ( $paged > 1 ) { $canonical = trailingslashit( $canonical ) . trailingslashit( $wp_rewrite->pagination_base ) . $paged; } } elseif ( $qo instanceof WP_Post ) { $canonical = get_permalink( $qo ); if ( $useCommentsPagination ) { $page = get_query_var( 'cpage' ); if ( $page > 1 ) { $canonical = trailingslashit( $canonical ) . $wp_rewrite->comments_pagination_base . '-' . $page; } } } if ( $canonical ) { return user_trailingslashit( $canonical ); } } /** * Find current slug by product SKU * * @param string $sku * * @return string */ protected function findSlugBySku( $sku ) { global $wpdb ; $skuId = $wpdb->get_row( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = %s AND meta_key = '_sku'", array( $sku ) ), ARRAY_A ); if ( isset( $skuId['post_id'] ) ) { $postSlug = get_post_field( 'post_name', $skuId['post_id'] ); if ( '' !== $postSlug ) { return $postSlug; } } return $sku; } /** * Check if woocommerce category exists in request * * @param array $request * * @return boolean */ protected function checkIfWooCategoryExists( $request ) { if ( !empty($this->options['category']) && in_array( $this->options['product'], array( 'category_slug', 'hierarchical' ) ) ) { if ( array_key_exists( self::WOO_CATEGORY, $request ) ) { return true; } } return false; } }