WC_Admin_Marketplace_Promotions::fetch_marketplace_promotions()
Get promotions to show in the Woo in-app marketplace. Only run on selected pages in the main WooCommerce menu in wp-admin. Loads promotions in transient with one day life.
Метод класса: WC_Admin_Marketplace_Promotions{}
Хуки из метода
Возвращает
null
. Ничего (null).
Использование
$result = WC_Admin_Marketplace_Promotions::fetch_marketplace_promotions();
Код WC_Admin_Marketplace_Promotions::fetch_marketplace_promotions() WC Admin Marketplace Promotions::fetch marketplace promotions WC 8.7.0
public static function fetch_marketplace_promotions() { $url = 'https://woo.com/wp-json/wccom-extensions/3.0/promotions'; $promotions = get_transient( self::TRANSIENT_NAME ); if ( false !== $promotions ) { return; } $fetch_options = array( 'auth' => true, 'country' => true, ); $raw_promotions = WC_Admin_Addons::fetch( $url, $fetch_options ); // phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores if ( is_wp_error( $raw_promotions ) ) { /** * Allows connection error to be handled. * * @since 8.7 */ do_action( 'woocommerce_page_wc-addons_connection_error', $raw_promotions->get_error_message() ); } $response_code = (int) wp_remote_retrieve_response_code( $raw_promotions ); if ( 200 !== $response_code ) { /** * Allows connection error to be handled. * * @since 8.7 */ do_action( 'woocommerce_page_wc-addons_connection_error', $response_code ); } $promotions = json_decode( wp_remote_retrieve_body( $raw_promotions ), true ); if ( empty( $promotions ) || ! is_array( $promotions ) ) { /** * Allows connection error to be handled. * * @since 8.7 */ do_action( 'woocommerce_page_wc-addons_connection_error', 'Empty or malformed response' ); } // phpcs:enable WordPress.NamingConventions.ValidHookName.UseUnderscores if ( $promotions ) { // Filter out any expired promotions. $promotions = self::get_active_promotions( $promotions ); set_transient( self::TRANSIENT_NAME, $promotions, DAY_IN_SECONDS ); } }