settings_init(); $this->settings_save(); } /** * Init our settings. */ public function settings_init() { add_settings_section( 'woocommerce-permalink', __( 'Product permalinks', 'woocommerce' ), array( $this, 'settings' ), 'permalink' ); add_settings_field( 'woocommerce_product_category_slug', __( 'Product category base', 'woocommerce' ), array( $this, 'product_category_slug_input' ), 'permalink', 'optional' ); add_settings_field( 'woocommerce_product_tag_slug', __( 'Product tag base', 'woocommerce' ), array( $this, 'product_tag_slug_input' ), 'permalink', 'optional' ); add_settings_field( 'woocommerce_product_attribute_slug', __( 'Product attribute base', 'woocommerce' ), array( $this, 'product_attribute_slug_input' ), 'permalink', 'optional' ); $this->permalinks = wc_get_permalink_structure(); } /** * Show a slug input box. */ public function product_category_slug_input() { ?> /attribute-name/attribute/ shop would make your product links like %sshop/sample-product/. This setting affects product URLs only, not things such as product categories.', 'woocommerce' ), esc_url( home_url( '/' ) ) ) ) ); $shop_page_id = wc_get_page_id( 'shop' ); $base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) ); $product_base = _x( 'product', 'default-slug', 'woocommerce' ); $structures = array( 0 => '', 1 => '/' . trailingslashit( $base_slug ), 2 => '/' . trailingslashit( $base_slug ) . trailingslashit( '%product_cat%' ), ); ?> 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ); if ( $shop_page_id && stristr( trim( $permalinks['product_base'], '/' ), $shop_permalink ) ) { $permalinks['use_verbose_page_rules'] = true; } update_option( 'woocommerce_permalinks', $permalinks ); wc_restore_locale(); } } } return new WC_Admin_Permalink_Settings();