wc_get_permalink_structure()WC 3.0.0

Get permalink settings for things like products and taxonomies.

As of 3.3.0, the permalink settings are stored to the option instead of being blank and inheritting from the locale. This speeds up page loading times by negating the need to switch locales on each page load.

This is more inline with WP core behavior which does not localize slugs.

No Hooks.

Return

Array.

Usage

wc_get_permalink_structure();

Changelog

Since 3.0.0 Introduced.

wc_get_permalink_structure() code WC 8.7.0

function wc_get_permalink_structure() {
	$saved_permalinks = (array) get_option( 'woocommerce_permalinks', array() );
	$permalinks       = wp_parse_args(
		array_filter( $saved_permalinks ),
		array(
			'product_base'           => _x( 'product', 'slug', 'woocommerce' ),
			'category_base'          => _x( 'product-category', 'slug', 'woocommerce' ),
			'tag_base'               => _x( 'product-tag', 'slug', 'woocommerce' ),
			'attribute_base'         => '',
			'use_verbose_page_rules' => false,
		)
	);

	if ( $saved_permalinks !== $permalinks ) {
		update_option( 'woocommerce_permalinks', $permalinks );
	}

	$permalinks['product_rewrite_slug']   = untrailingslashit( $permalinks['product_base'] );
	$permalinks['category_rewrite_slug']  = untrailingslashit( $permalinks['category_base'] );
	$permalinks['tag_rewrite_slug']       = untrailingslashit( $permalinks['tag_base'] );
	$permalinks['attribute_rewrite_slug'] = untrailingslashit( $permalinks['attribute_base'] );

	return $permalinks;
}