merce_cart_page_endpoint' === $option ) { return $this->sync_endpoint_with_page( CartTemplate::get_placeholder_page(), 'cart', $value ); } return $value; } /** * Syncs the provided permalink with the actual WP page. * * @param WP_Post|null $page The page object, or null if it does not exist. * @param string $page_slug The identifier for the page e.g. cart, checkout. * @param string $permalink The new permalink to use. * @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 ) { if ( ! $page ) { $updated_page_id = wc_create_page( esc_sql( $permalink ), 'woocommerce_' . $page_slug . '_page_id', $page_slug, '', '', 'publish' ); } else { $updated_page_id = wp_update_post( [ 'ID' => $page->ID, 'post_name' => esc_sql( $permalink ), ] ); } // Get post again in case slug was updated with a suffix. if ( $updated_page_id && ! is_wp_error( $updated_page_id ) ) { return get_post( $updated_page_id )->post_name; } return $permalink; } }