'WooCommerce Addons Page' ) ); if ( ! is_wp_error( $raw_featured ) ) { $featured = json_decode( wp_remote_retrieve_body( $raw_featured ) ); if ( $featured ) { set_transient( 'wc_addons_featured', $featured, WEEK_IN_SECONDS ); } } } if ( is_object( $featured ) ) { self::output_featured_sections( $featured->sections ); return $featured; } } /** * Build url parameter string * * @param string $category * @param string $term * @param string $country * * @return string url parameter string */ public static function build_parameter_string( $category, $term, $country ) { $paramters = array( 'category' => $category, 'term' => $term, 'country' => $country, ); return '?' . http_build_query( $paramters ); } /** * Call API to get extensions * * @param string $category * @param string $term * @param string $country * * @return array of extensions */ public static function get_extension_data( $category, $term, $country ) { $parameters = self::build_parameter_string( $category, $term, $country ); $raw_extensions = wp_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/search' . $parameters ); if ( ! is_wp_error( $raw_extensions ) ) { $addons = json_decode( wp_remote_retrieve_body( $raw_extensions ) )->products; } return $addons; } /** * Get sections for the addons screen * * @return array of objects */ public static function get_sections() { $addon_sections = get_transient( 'wc_addons_sections' ); if ( false === ( $addon_sections ) ) { $raw_sections = wp_safe_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/categories' ); if ( ! is_wp_error( $raw_sections ) ) { $addon_sections = json_decode( wp_remote_retrieve_body( $raw_sections ) ); if ( $addon_sections ) { set_transient( 'wc_addons_sections', $addon_sections, WEEK_IN_SECONDS ); } } } return apply_filters( 'woocommerce_addons_sections', $addon_sections ); } /** * Get section for the addons screen. * * @param string $section_id * * @return object|bool */ public static function get_section( $section_id ) { $sections = self::get_sections(); if ( isset( $sections[ $section_id ] ) ) { return $sections[ $section_id ]; } return false; } /** * Get section content for the addons screen. * * @param string $section_id * * @return array */ public static function get_section_data( $section_id ) { $section = self::get_section( $section_id ); $section_data = ''; if ( ! empty( $section->endpoint ) ) { if ( false === ( $section_data = get_transient( 'wc_addons_section_' . $section_id ) ) ) { $raw_section = wp_safe_remote_get( esc_url_raw( $section->endpoint ), array( 'user-agent' => 'WooCommerce Addons Page' ) ); if ( ! is_wp_error( $raw_section ) ) { $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); if ( ! empty( $section_data->products ) ) { set_transient( 'wc_addons_section_' . $section_id, $section_data, WEEK_IN_SECONDS ); } } } } return apply_filters( 'woocommerce_addons_section_data', $section_data->products, $section_id ); } /** * Handles the outputting of a contextually aware Storefront link (points to child themes if Storefront is already active). */ public static function output_storefront_button() { $template = get_option( 'template' ); $stylesheet = get_option( 'stylesheet' ); if ( 'storefront' === $template ) { if ( 'storefront' === $stylesheet ) { $url = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/'; $text = __( 'Need a fresh look? Try Storefront child themes', 'woocommerce' ); $utm_content = 'nostorefrontchildtheme'; } else { $url = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/'; $text = __( 'View more Storefront child themes', 'woocommerce' ); $utm_content = 'hasstorefrontchildtheme'; } } else { $url = 'https://woocommerce.com/storefront/'; $text = __( 'Need a theme? Try Storefront', 'woocommerce' ); $utm_content = 'nostorefront'; } $url = add_query_arg( array( 'utm_source' => 'addons', 'utm_medium' => 'product', 'utm_campaign' => 'woocommerceplugin', 'utm_content' => $utm_content, ), $url ); echo '' . esc_html( $text ) . '' . "\n"; } /** * Handles the outputting of a banner block. * * @param object $block */ public static function output_banner_block( $block ) { ?>
container ) && 'column_container_start' === $block->container ) { ?>description ); ?>
items as $item ) : ?>description ); ?>
description ); ?>
description ); ?>