=> 'slug', ) ); if ( $this->polyLang->options['hide_default'] ) { $languages = array_diff( $languages, array( $this->polyLang->options['default_lang'] ) ); } if ( !empty($languages) ) { return $wp_rewrite->root . (( $this->polyLang->options['rewrite'] ? '' : 'language/' )) . '(' . implode( '|', $languages ) . ')/'; } } return false; } private function getProductBase() { if ( is_null( $this->productBase ) ) { $permalinkStructure = wc_get_permalink_structure(); $this->productBase = $permalinkStructure['product_rewrite_slug']; } return $this->productBase; } private function addPostParentLink( $permalink, $post, $hierarchical ) { if ( false === strpos( $permalink, '%product_cat%' ) ) { return $permalink; } $term = $this->getProductCategory( $post ); if ( $term ) { $slug = $this->buildTermPath( $term, $hierarchical ); $permalink = str_replace( '%product_cat%', $slug, $permalink ); } return $permalink; } private function buildTermPath( $term, $hierarchical, $suffix = false ) { //urldecode used here to fix copied url via ctrl+c $slug = urldecode( $term->slug ); if ( $hierarchical && $term->parent ) { $ancestors = get_ancestors( $term->term_id, 'product_cat' ); foreach ( $ancestors as $ancestor ) { $ancestor_object = get_term( $ancestor, 'product_cat' ); $slug = urldecode( $ancestor_object->slug ) . '/' . $slug; } } return ( $suffix ? $slug . $suffix : $slug ); } private function getProductCategory( $product ) { $term = null; if ( !empty($this->options['use_primary_category']) ) { $term = $this->getSeoPrimaryTerm( $product ); } if ( !$term instanceof \WP_Term ) { $term = $this->getWcPrimaryTerm( $product ); } if ( $term instanceof \WP_Term ) { return $term; } return null; } private function getSeoPrimaryTerm( $product ) { if ( $this->checkSeoPlugin() ) { $primaryTerm = yoast_get_primary_term_id( self::WOO_CAT, $product->ID ); return get_term( $primaryTerm ); } return null; } private function getWcPrimaryTerm( $product ) { $terms = get_the_terms( $product->ID, 'product_cat' ); if ( empty($terms) ) { return null; } if ( function_exists( 'wp_list_sort' ) ) { $terms = wp_list_sort( $terms, 'term_id', 'DESC' ); } else { usort( $terms, '_usort_terms_by_ID' ); } $category_object = apply_filters( 'wc_product_post_type_link_product_cat', $terms[0], $terms, $product ); $category_object = get_term( $category_object, 'product_cat' ); return $category_object; } private function isHierarchical( $type ) { return 'hierarchical' === $type; } /** * Check that seo plugin is enabled and available to use * * @return bool */ protected function checkSeoPlugin() { if ( !function_exists( 'is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } return function_exists( 'is_plugin_active' ) && defined( 'WPSEO_BASENAME' ) && is_plugin_active( WPSEO_BASENAME ) && function_exists( 'yoast_get_primary_term_id' ); } /** * Check that WPML plugin is enabled and available to use * * @return bool */ protected function checkWpmlPlugin() { return class_exists( 'SitePress' ); } /** * Replace current post slug with woocommerce SKU * * @param string $permalink * @param integer $postID * * @return string */ protected function replaceSlugWithSku( $permalink, $postID ) { $skuString = get_post_meta( $postID, '_sku', true ); if ( '' !== $skuString ) { if ( 'sku' === $this->options['sku'] ) { return str_replace( basename( $permalink ), $skuString, $permalink ); } } return $permalink; } /** * Add parameters to permalink * * @param string $permalink * * @return string */ protected function addParamsToPermalink( $permalink ) { $parsedUrl = parse_url( $permalink, PHP_URL_QUERY ); parse_str( $parsedUrl, $output ); if ( isset( $output['lang'] ) ) { return $permalink; } global $sitepress ; $isGetParamUrlFormat = apply_filters( 'wpml_setting', 0, 'language_negotiation_type' ) == '3'; if ( $sitepress->get_default_language() != ICL_LANGUAGE_CODE && $isGetParamUrlFormat ) { return add_query_arg( array( 'lang' => ICL_LANGUAGE_CODE, ), $permalink ); } return $permalink; } }