Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix: sync_endpoint_with_page should use a matching slug if it exists …
Browse files Browse the repository at this point in the history
…instead of creating a new page (#10640)
  • Loading branch information
mikejolley authored and nielslange committed Aug 21, 2023
1 parent b351cdf commit c68583b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ public function update_template_permalink( $value, $option ) {
* @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 ),
Expand Down

0 comments on commit c68583b

Please sign in to comment.