WC_Admin_Permalink_Settings::settings
Show the settings.
Метод класса: WC_Admin_Permalink_Settings{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WC_Admin_Permalink_Settings = new WC_Admin_Permalink_Settings(); $WC_Admin_Permalink_Settings->settings();
Код WC_Admin_Permalink_Settings::settings() WC Admin Permalink Settings::settings WC 11.3.0
<?php
public function settings() {
/* translators: %s: Home URL */
echo wp_kses_post( wpautop( sprintf( __( 'If you like, you may enter custom structures for your product URLs here. For example, using <code>shop</code> would make your product links like <code>%sshop/sample-product/</code>. This setting affects product URLs only, not things such as product categories.', 'woocommerce' ), esc_url( home_url( '/' ) ) ) ) );
/*
* Resolve the Shop page and the translated slugs inside the same window settings_save()
* opens, so the values compared below are the values a save would store.
*
* wc_get_page_id() is resolved here too because settings_save() resolves it inside its own
* window, and the woocommerce_get_shop_page_id filter multilingual plugins attach to can
* return a different page per locale.
*
* This holds only for a persisted product_base: wc_get_permalink_structure() initializes a
* missing one in the request locale, outside any window, before this screen renders.
* See https://github.com/woocommerce/woocommerce/issues/67507.
*/
wc_switch_to_site_locale();
$shop_page_id = wc_get_page_id( 'shop' );
$base_slug = urldecode( $this->get_shop_base_slug( $shop_page_id ) );
// The value each radio posts. The Shop entries exist only when their rows render below, so
// a stored base matching a hidden row reports as Custom instead of checking nothing.
$structures = array( 0 => '' );
if ( $shop_page_id ) {
$structures[1] = '/' . trailingslashit( $base_slug );
$structures[2] = '/' . trailingslashit( $base_slug ) . trailingslashit( '%product_cat%' );
}
// What a save would store for each of them, so the comparison below cannot drift from
// settings_save().
$stored_forms = array_map( array( $this, 'get_stored_product_base' ), $structures );
wc_restore_locale();
$default_product_base = $stored_forms[0];
$stored_product_base = $this->permalinks['product_base'];
$default_product_structure = trailingslashit( '/' . ltrim( $default_product_base, '/' ) );
// The index of the predefined structure the stored base corresponds to, or false for a custom one.
$selected_structure = array_search( $stored_product_base, $stored_forms, true );
$product_permalink_structure = 0 === $selected_structure
? $default_product_structure
: ( $stored_product_base ? trailingslashit( $stored_product_base ) : '' );
?>
<table class="form-table wc-permalink-structure">
<tbody>
<tr>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[0] ); ?>" data-permalink-structure="<?php echo esc_attr( $default_product_structure ); ?>" class="wctog" <?php checked( 0 === $selected_structure ); ?> /> <?php esc_html_e( 'Default', 'woocommerce' ); ?></label></th>
<td><code class="default-example"><?php echo esc_html( home_url() ); ?>/?product=sample-product</code> <code class="non-default-example"><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $default_product_base ); ?>/sample-product/</code></td>
</tr>
<?php if ( $shop_page_id ) : ?>
<tr>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" data-permalink-structure="<?php echo esc_attr( $structures[1] ); ?>" class="wctog" <?php checked( 1 === $selected_structure ); ?> /> <?php esc_html_e( 'Shop base', 'woocommerce' ); ?></label></th>
<td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/sample-product/</code></td>
</tr>
<tr>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[2] ); ?>" data-permalink-structure="<?php echo esc_attr( $structures[2] ); ?>" class="wctog" <?php checked( 2 === $selected_structure ); ?> /> <?php esc_html_e( 'Shop base with category', 'woocommerce' ); ?></label></th>
<td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/product-category/sample-product/</code></td>
</tr>
<?php endif; ?>
<tr>
<th><label><input name="product_permalink" id="woocommerce_custom_selection" type="radio" value="custom" class="tog" <?php checked( false === $selected_structure ); ?> />
<?php esc_html_e( 'Custom base', 'woocommerce' ); ?></label></th>
<td>
<input name="product_permalink_structure" id="woocommerce_permalink_structure" type="text" value="<?php echo esc_attr( $product_permalink_structure ); ?>" class="regular-text code" aria-label="<?php esc_attr_e( 'Custom product permalink base', 'woocommerce' ); ?>" aria-describedby="woocommerce_permalink_structure_description"> <span class="description" id="woocommerce_permalink_structure_description"><?php esc_html_e( 'Enter a custom base to use. A base must be set or WordPress will use default instead.', 'woocommerce' ); ?></span>
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( 'wc-permalinks', 'wc-permalinks-nonce' ); ?>
<script type="text/javascript">
jQuery( function() {
jQuery('input.wctog').on( 'change', function() {
jQuery('#woocommerce_permalink_structure').val( jQuery( this ).attr( 'data-permalink-structure' ) );
});
jQuery('.permalink-structure input').on( 'change', function() {
jQuery('.wc-permalink-structure').find('code.non-default-example, code.default-example').hide();
if ( jQuery(this).val() ) {
jQuery('.wc-permalink-structure code.non-default-example').show();
jQuery('.wc-permalink-structure input').prop('disabled', false);
} else {
jQuery('.wc-permalink-structure code.default-example').show();
jQuery('.wc-permalink-structure input:eq(0)').trigger( 'click' );
jQuery('.wc-permalink-structure input').attr('disabled', 'disabled');
}
});
jQuery('.permalink-structure input:checked').trigger( 'change' );
// Selecting Custom base takes a click or a typed character, the pair core binds to
// its own structure field. Focus alone must not: the radios share one tab stop, so
// tabbing forward lands here, and flipping on focus would move the checked radio
// off the structure the store actually uses.
jQuery('#woocommerce_permalink_structure').on( 'click input', function(){
jQuery('#woocommerce_custom_selection').trigger( 'click' );
} );
} );
</script>
<?php
}