Coming soon mode - Match shop page when permalink structure is set to plain (#50567)

* Match shop page when permalink structure is set to plain

* Revert uninteded change

* Match post types

* Check for param

* Add test for post_type check

* Fix tests

* Add changefile(s) from automation for the following project(s): woocommerce

* Use wp_parse_url

* Test returning false

* Lint fixes

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Moon 2024-08-20 19:50:00 -07:00 committed by GitHub
parent d07cb35247
commit dac8fa8eba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Treat post_type=product as a shop page.

View File

@ -150,6 +150,18 @@ class WCAdminHelper {
}
$normalized_path = self::get_normalized_url_path( $url );
$params = array(
'post_type' => 'product',
);
parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $url_params );
foreach ( $params as $key => $param ) {
if ( isset( $url_params[ $key ] ) && $url_params[ $key ] === $param ) {
return true;
}
}
// WC store pages.
$store_pages = array(
'shop' => wc_get_page_id( 'shop' ),
@ -185,6 +197,7 @@ class WCAdminHelper {
}
$permalink = get_permalink( $page_id );
if ( ! $permalink ) {
continue;
}

View File

@ -257,6 +257,19 @@ class WC_Admin_Tests_Admin_Helper extends WC_Unit_Test_Case {
}
}
/**
* Test is_store_page with the defined post_type param.
*/
public function test_is_store_page_with_post_type() {
// Test with post_type=product.
$this->assertTrue( WCAdminHelper::is_store_page( 'https://example.com/?post_type=product' ) );
// Test with post_type=product and other params.
$this->assertTrue( WCAdminHelper::is_store_page( 'https://example.com/test?param1=value1&post_type=product&param2=value2' ) );
// should return false if post_type is not product.
$this->assertFalse( WCAdminHelper::is_store_page( 'https://example.com/test?param1=value1&param2=value2' ) );
}
/** Test product archive link is store page even if shop page not set. */
public function test_is_store_page_even_if_shop_page_not_set() {
$shop_page_id = get_option( 'woocommerce_shop_page_id' );