$current_niche, ), array( 'data-loop-product-layout' => ProductCatalogService::get_product_layout(), 'data-brandy-blocks-installed' => is_brandy_blocks_installed() ? 'true' : 'false', ) ) ); } } if ( ! function_exists( 'brandy_get_editable_class' ) ) { /** * Returns class for wrapper when in customize mode */ function brandy_get_editable_class( $edit_type = 'section' ) { if ( is_customize_preview() ) { return 'row' === $edit_type ? 'editable-part editable-row-part' : 'editable-part editable-element-part'; } return ''; } } if ( ! function_exists( 'brandy_get_editable_attributes' ) ) { /** * Returns attrubutes for wrapper when in customize mode * * @param string $section_id Section id. */ function brandy_get_editable_attributes( string $section_id ) { return true ? "data-section-id=$section_id" : ''; } } if ( ! function_exists( 'brandy_print_dom_attributes' ) ) { /** * Print DOM element attributes from given array * * @param array $attributes * * @return void */ function brandy_print_dom_attributes( $attributes ) { foreach ( $attributes as $attr_name => $attr_value ) { echo esc_attr( $attr_name ); if ( ! empty( $attr_value ) ) { echo '="' . esc_attr( $attr_value ) . '"'; } } } } if ( ! function_exists( 'brandy_get_devices' ) ) { /** * Returns all device of theme * * @return array */ function brandy_get_devices() { return array( 'desktop', 'tablet', 'mobile' ); } } if ( ! function_exists( 'brandy_enabled_devices_classes' ) ) { /** * Return classes which indicate which device is hidden * * @param array $enabled_devices List enabled devices. * * @return string */ function brandy_enabled_devices_classes( $enabled_devices ) { if ( ! is_array( $enabled_devices ) ) { return ''; } $hidden_devices = array_diff( array( 'desktop', 'mobile' ), $enabled_devices ); $classes = implode( ' ', array_map( function( $device ) { if ( 'mobile' === $device ) { return 'hidden-md hidden-sm'; } return 'hidden-lg'; }, $hidden_devices ) ); return $classes; } } if ( ! function_exists( 'brandy_render_badge' ) ) { /** * Render Brandy badge * * @param string $number * @param string $attrs * @param string $class * * @return void */ function brandy_render_badge( $number, $attrs = '', $class = '' ) { get_template_part( 'template-parts/common/badge', '', array( 'number' => $number, 'attrs' => $attrs, 'class' => $class, ) ); } } if ( ! function_exists( 'brandy_render_icon' ) ) { /** * Render Brandy icon * * @param string $icon Icon source * @param string $class * @param string $attrs * * @return void */ function brandy_render_icon( $icon, $attrs = array() ) { get_template_part( 'template-parts/common/icon', '', array( 'icon' => $icon, 'attrs' => $attrs, ) ); } } if ( ! function_exists( 'brandy_wishlist' ) ) { /** * Render wishlist content template */ function brandy_wishlist( $settings ) { get_template_part( 'template-parts/wishlist/wishlist-drawer', '', array( 'settings' => $settings, ) ); } } if ( ! function_exists( 'brandy_get_rating_html' ) ) { /** * Display product ratings * * @param int $rating Rating for this product (overall or single) * @param int $count Total reviews for this product * @param boolean $only_stars Show only stars or not * @param boolean $total_reviews . */ function brandy_get_rating_html( $product, $rating, $rating_count = 0, $show_only_stars = false, $show_overall = false, $review_count = 0 ) { // if ( empty( $product ) ) { // return; // } brandy_get_template_part( 'template-parts/rating', null, array( // 'product' => $product, 'rating' => $rating, 'rating_count' => $rating_count, 'show_only_stars' => $show_only_stars, 'review_count' => $review_count, 'show_overall' => $show_overall, ) ); } } if ( ! function_exists( 'brandy_get_current_page_id' ) ) { /** * Get current page ID */ function brandy_get_current_page_id() { if ( is_front_page() ) { return get_option( 'page_on_front' ); } elseif ( is_home() ) { return get_option( 'page_for_posts' ); } elseif ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) { return wc_get_page_id( 'shop' ); } else { return get_the_ID(); } } } if ( ! function_exists( 'brandy_render_button_link' ) ) { function brandy_render_button_link( $args ) { $default_args = array( 'text' => __( 'Button', 'brandy' ), 'href' => '#', 'class' => '', ); $args = wp_parse_args( $args, $default_args ); ?> __( 'Button', 'brandy' ), 'href' => '#', 'class' => '', ); $args = wp_parse_args( $args, $default_args ); ?> %s', ! empty( $args['class'] ) ? esc_attr( ' ' . $args['class'] ) : '', esc_attr( ! empty( $args['href'] ) ? ( 'href="' . esc_url( $args['href'] ) . '"' ) : '' ), esc_html( $args['text'] ) ) ?> get_queried_object_id(); return $page_id; } } if ( ! function_exists( 'brandy_get_home_page_id' ) ) { /** * Get home page id. * Returns null home page isn't assigned. * * @return int|null Id for home page * * @since 1.0 */ function brandy_get_home_page_id() { $show_on_front = get_option( 'show_on_front' ); if ( 'page' !== $show_on_front ) { return null; } $home_page_id = get_option( 'page_on_front', null ); return $home_page_id; } } if ( ! function_exists( 'brandy_is_home' ) ) { /** * Check is homepage * * @return bool * * @since 1.0 */ function brandy_is_home() { $home_page_id = brandy_get_home_page_id(); return is_home() || ( brandy_get_current_page_id() == $home_page_id ); } } if ( ! function_exists( 'brandy_is_thankyou_page' ) ) { /** * Check if current page is thank you page. * * @return boolean */ function brandy_is_thankyou_page() { return \is_wc_installed() && function_exists( 'is_wc_endpoint_url' ) && \is_wc_endpoint_url( 'order-received' ); } } if ( ! function_exists( 'brandy_get_blog_page_id' ) ) { /** * Get blog page id. * Returns null blog page isn't assigned. * * @return int|null Id for blog page * * @since 1.0 */ function brandy_get_blog_page_id() { $show_on_front = get_option( 'show_on_front' ); if ( 'page' !== $show_on_front ) { return null; } $blog_page_id = get_option( 'page_for_posts', null ); return $blog_page_id; } } if ( ! function_exists( 'brandy_get_blog_page_url' ) ) { /** * Get blog page url. * Returns # blog page isn't assigned. * * @return string Url for blog page * * @since 1.0 */ function brandy_get_blog_page_url() { $blog_page_id = brandy_get_blog_page_id(); if ( empty( $blog_page_id ) ) { return '#'; } $url = add_query_arg( array( 'page_id' => $blog_page_id ), home_url() ); return $url; } } if ( ! function_exists( 'brandy_get_shop_page_id' ) ) { /** * Get shop page ID. * * @return int|null Shop page ID. */ function brandy_get_shop_page_id() { return function_exists( 'wc_get_page_id' ) ? \wc_get_page_id( 'shop' ) : null; } } if ( ! function_exists( 'brandy_get_shop_page_url' ) ) { /** * Get shop page url. * Returns # when WooCommerce is not installed. * * @return string Url for shop page * * @since 1.0 */ function brandy_get_shop_page_url() { return function_exists( 'wc_get_page_permalink' ) ? \wc_get_page_permalink( 'shop' ) : '#'; } } if ( ! function_exists( 'brandy_get_cart_page_id' ) ) { /** * Get cart page ID. * * @return int|null Cart page ID. */ function brandy_get_cart_page_id() { return function_exists( 'wc_get_page_id' ) ? \wc_get_page_id( 'cart' ) : null; } } if ( ! function_exists( 'brandy_get_cart_page_url' ) ) { /** * Get cart page url. * Returns # when WooCommerce is not installed. * * @return string Url for cart page * * @since 1.0 */ function brandy_get_cart_page_url() { return function_exists( 'wc_get_cart_url' ) ? \wc_get_cart_url() : '#'; } } if ( ! function_exists( 'brandy_get_checkout_page_id' ) ) { /** * Get checkout page ID. * * @return int|null Checkout page ID. */ function brandy_get_checkout_page_id() { return function_exists( 'wc_get_page_id' ) ? \wc_get_page_id( 'checkout' ) : null; } } if ( ! function_exists( 'brandy_get_checkout_page_url' ) ) { /** * Get checkout page url. * Returns # when WooCommerce is not installed. * * @return string Url for checkout page * * @since 1.0 */ function brandy_get_checkout_page_url() { return function_exists( 'wc_get_checkout_url' ) ? \wc_get_checkout_url() : '#'; } } if ( ! function_exists( 'brandy_get_contact_us_page_id' ) ) { /** * Get contact us page id. * Returns null contact us page isn't assigned. * * @return int|null Id for contact us page * * @since 1.1.7 */ function brandy_get_contact_us_page_id() { $pages = get_posts( array( 'post_type' => 'page', 'meta_key' => '_wp_page_template', 'meta_value' => 'contact-us', 'posts_per_page' => 1, ) ); if ( ! empty( $pages ) ) { return $pages[0]->ID; } return null; } } if ( ! function_exists( 'brandy_get_contact_us_page_url' ) ) { /** * Get contact us page url. * Returns null contact us page isn't assigned. * * @return string|null Url for contact us page * * @since 1.1.7 */ function brandy_get_contact_us_page_url() { $blog_page_id = brandy_get_contact_us_page_id(); if ( empty( $blog_page_id ) ) { return '#'; } $url = add_query_arg( array( 'page_id' => $blog_page_id ), home_url() ); return $url; } } if ( ! function_exists( 'brandy_get_about_us_page_id' ) ) { /** * Get about us page id. * Returns null about us page isn't assigned. * * @return int|null Id for about us page * * @since 1.1.7 */ function brandy_get_about_us_page_id() { $pages = get_posts( array( 'post_type' => 'page', 'meta_key' => '_wp_page_template', 'meta_value' => 'about-us', 'posts_per_page' => 1, ) ); if ( ! empty( $pages ) ) { return $pages[0]->ID; } return null; } } if ( ! function_exists( 'brandy_get_about_us_page_url' ) ) { /** * Get about us page url. * Returns null about us page isn't assigned. * * @return string|null Url for about us page * * @since 1.1.7 */ function brandy_get_about_us_page_url() { $blog_page_id = brandy_get_about_us_page_id(); if ( empty( $blog_page_id ) ) { return '#'; } $url = add_query_arg( array( 'page_id' => $blog_page_id ), home_url() ); return $url; } } if ( ! function_exists( 'brandy_get_login_url' ) ) { /** * Get login page url. * Returns wp login page when WooCommerce is not installed. * * @return string Url for login page * * @since 1.0 */ function brandy_get_login_url() { return function_exists( 'wc_get_account_endpoint_url' ) ? \wc_get_account_endpoint_url( 'dashboard' ) : wp_login_url(); } } if ( ! function_exists( 'brandy_get_logout_url' ) ) { /** * Get logout page url. * Returns wp logout page when WooCommerce is not installed. * * @return string Url for logout page * * @since 1.0 */ function brandy_get_logout_url() { return function_exists( 'wc_get_account_endpoint_url' ) ? \wc_get_account_endpoint_url( 'customer-logout' ) : wp_logout_url(); } } if ( ! function_exists( 'brandy_get_terms_and_conditions_page_id' ) ) { /** * Get terms and conditions page id. * Returns null terms and conditions page isn't assigned. * * @return int|null Id for terms and conditions page * * @since 1.4 */ function brandy_get_terms_and_conditions_page_id() { return get_option( 'woocommerce_terms_page_id', null ); } } if ( ! function_exists( 'brandy_get_terms_and_conditions_page_url' ) ) { /** * Get logout page url. * Returns wp logout page when WooCommerce is not installed. * * @return string Url for logout page * * @since 1.4 */ function brandy_get_terms_and_conditions_page_url() { $terms_page_id = brandy_get_terms_and_conditions_page_id(); if ( empty( $terms_page_id ) ) { return '#'; } $url = add_query_arg( array( 'page_id' => $terms_page_id ), home_url() ); return $url; } } if ( ! function_exists( 'brandy_get_privacy_policy_page_id' ) ) { /** * Get privacy policy page id. * Returns null privacy policy page isn't assigned. * * @return int|null Id for privacy policy page * * @since 1.4 */ function brandy_get_privacy_policy_page_id() { return get_option( 'wp_page_for_privacy_policy', null ); } } if ( ! function_exists( 'brandy_get_privacy_policy_page_url' ) ) { /** * Get privacy policy page url. * Returns null privacy policy page isn't assigned. * * @return string|null Url for privacy policy page * * @since 1.4 */ function brandy_get_privacy_policy_page_url() { $privacy_page_id = brandy_get_privacy_policy_page_id(); if ( empty( $privacy_page_id ) ) { return '#'; } $url = add_query_arg( array( 'page_id' => $privacy_page_id ), home_url() ); return $url; } }