|null */ public static function collect(): ?array { if ( ! Module::active() || ! function_exists( 'wc_get_page_permalink' ) ) { return null; } $pages = array(); foreach ( array( 'shop', 'cart', 'checkout' ) as $kind ) { $pages[ $kind ] = (string) wc_get_page_permalink( $kind ); } if ( function_exists( 'wc_get_products' ) ) { $products = wc_get_products( array( 'status' => 'publish', 'visibility' => 'catalog', 'limit' => 1, 'orderby' => 'date', 'order' => 'DESC', 'return' => 'ids', ) ); if ( is_array( $products ) && isset( $products[0] ) ) { $pages['product'] = (string) get_permalink( (int) $products[0] ); } } return self::clean( $pages, (string) home_url( '/' ) ); } /** * Pure filtering: drops empty values and pages that fall back to the home page (page not set up). * * @param array $pages Kind => URL. * @param string $home Home URL. * @return array */ public static function clean( array $pages, string $home ): array { $out = array(); foreach ( $pages as $kind => $url ) { if ( '' !== $url && untrailingslashit( $url ) !== untrailingslashit( $home ) && 0 === strpos( $url, 'http' ) ) { $out[ $kind ] = substr( $url, 0, 500 ); } } return $out; } }