'slug' ) ); if ( count( $languages ) < 2 ) { return $schema; } if ( ! isset( $schema['sameAs'] ) ) { $schema['sameAs'] = array(); } $product_id = $product->get_id(); foreach ( $languages as $lang_slug ) { $translated_id = pll_get_post( $product_id, $lang_slug ); if ( $translated_id && $translated_id !== $product_id ) { $url = get_permalink( $translated_id ); if ( $url ) { $schema['sameAs'][] = $url; } } } // Add current language. if ( function_exists( 'pll_current_language' ) ) { $current_lang = pll_current_language( 'slug' ); if ( $current_lang ) { $schema['inLanguage'] = $current_lang; } } return $schema; } /** * Trigger feed generation for each active language. * * @param string $feed_type The feed type that was generated. * * @return void */ public function trigger_language_feeds( string $feed_type ): void { $languages = pll_languages_list( array( 'fields' => 'slug' ) ); if ( count( $languages ) < 2 ) { return; } foreach ( $languages as $lang_slug ) { if ( function_exists( 'PLL' ) && method_exists( PLL(), 'curlang' ) ) { // Switch Polylang context (best effort). do_action( 'pll_language', $lang_slug ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Third-party Polylang integration hook. } if ( function_exists( 'as_schedule_single_action' ) ) { as_schedule_single_action( time(), 'aicommerce_generate_feed', array( 'feed_type' => $feed_type . '_' . $lang_slug ) ); } } } }