WC_Post_Types::queue_rewrite_rules_on_shop_page_save
Queue rewrite rules to be flushed after the shop page (or its ancestors) gets saved.
Method of the class: WC_Post_Types{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Post_Types::queue_rewrite_rules_on_shop_page_save( $post_id, $post ): void;
- $post_id(int) (required)
- Post ID.
- $post(WP_Post|null)
- Post object.
Default:null
WC_Post_Types::queue_rewrite_rules_on_shop_page_save() WC Post Types::queue rewrite rules on shop page save code WC 11.1.2
private static function queue_rewrite_rules_on_shop_page_save( $post_id, $post = null ): void {
$post_id = absint( $post_id );
if ( ! $post_id || wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
return;
}
$post_status = $post instanceof WP_Post ? $post->post_status : get_post_status( $post_id );
$shop_page_id = wc_get_page_id( 'shop' );
// Keep the existing behavior where a trashed shop page still serves the product archive at its previous URL.
if ( 0 >= $shop_page_id || 'trash' === $post_status ) {
return;
}
if ( $shop_page_id === $post_id || in_array( $post_id, get_post_ancestors( $shop_page_id ), true ) ) {
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
}
}