Fix: sync_endpoint_with_page should use a matching slug if it exists instead of creating a new page (https://github.com/woocommerce/woocommerce-blocks/pull/10640)

This commit is contained in:
Mike Jolley 2023-08-17 16:26:49 +01:00 committed by GitHub
parent 4290a948a6
commit d46e286bf7
1 changed files with 9 additions and 0 deletions

View File

@ -952,6 +952,15 @@ class BlockTemplatesController {
* @return string THe actual permalink assigned to the page. May differ from $permalink if it was already taken.
*/
protected function sync_endpoint_with_page( $page, $page_slug, $permalink ) {
$matching_page = get_page_by_path( $permalink );
if ( $matching_page && 'publish' === $matching_page->post_status ) {
// Existing page matches given permalink; use its ID.
update_option( 'woocommerce_' . $page_slug . '_page_id', $matching_page->ID );
return $permalink;
}
// No matching page; either update current page (by ID stored in option table) or create a new page.
if ( ! $page ) {
$updated_page_id = wc_create_page(
esc_sql( $permalink ),