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 inheriting 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.

The use_verbose_page_rules key is kept for backward compatibility only. WooCommerce no longer writes or reads it - wc_fix_rewrite_rules() derives Shop subpage rules from the current product base and Shop page path instead - so its stored value is whatever the last save left behind.

No Hooks.

Returns

array.

Usage

wc_get_permalink_structure();

Changelog

Since 3.0.0 Introduced.

wc_get_permalink_structure() code WC 11.2.1

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;
}