theme_location ) { $nav_cart = wc_get_template_html( 'bs4-mini-cart.php' ); } if ( 'top' === $args->theme_location && ! has_nav_menu( 'top_secondary' ) ) { $nav_cart = wc_get_template_html( 'bs4-mini-cart.php' ); } } return $items . $nav_cart; } add_filter( 'wp_nav_menu_items', 'bs4_wc_display_top_nav_cart_menu_item', 10, 2 ); /** * Add image size to WordPress. Used for WooCommerce shopping cart product images. */ add_image_size( '50x50', 50, 50, true ); /** * Filters product categories list to make compatible with Bootstrap 4 badges. * * @param array $links List of terms to display. */ function bs4_wc_product_term_product_cat( $links ) { return bs4_wc_term_link_badge_html( $links, 'product_cat' ); } add_filter( 'term_links-product_cat', 'bs4_wc_product_term_product_cat' ); /** * Filters product tags list to make compatible with Bootstrap 4 badges. * * @param array $links List of terms to display. */ function bs4_wc_product_term_product_tag( $links ) { return bs4_wc_term_link_badge_html( $links, 'product_tag' ); } add_filter( 'term_links-product_tag', 'bs4_wc_product_term_product_tag' ); /** * Output HTML for WooCommerce taxonomy term link. * * @param array $html List of terms to display. * @param string $taxonomy Taxonomy name. */ function bs4_wc_term_link_badge_html( $html, $taxonomy ) { $badge_class = get_theme_mod( "wc_{$taxonomy}_badge_color", 'primary' ); $classes = ''; if ( $badge_class ) { $badge_class = 'bg-' . sanitize_html_class( $badge_class ); $classes = join( ' ', bs4_get_badge_class( $badge_class ) ); } $html = str_replace( ' rel="tag"', ' class="' . esc_attr( $classes ) . '" rel="tag"', $html ); return $html; } /** * Open wrapper for WooCommerce product list widget. */ function bs4_wc_before_widget_product_list() { return '
'; } add_filter( 'woocommerce_before_widget_product_list', 'bs4_wc_before_widget_product_list' ); /** * Close wrapper for WooCommerce product list widget. */ function bs4_wc_after_widget_product_list() { return '
'; } add_filter( 'woocommerce_after_widget_product_list', 'bs4_wc_after_widget_product_list' ); /** * When product is on sale then show Bootstrap badge component. * * @param string $sales_flash Sales flash HTML for products. */ function bs4_wc_sale_flash( $sales_flash ) { $badge_class = get_theme_mod( 'wc_sales_badge_color', 'primary' ); $classes = ''; if ( $badge_class && 'none' !== $badge_class ) { $badge_class = 'bg-' . sanitize_html_class( $badge_class ); $classes = join( ' ', bs4_get_badge_class( $badge_class ) ); } // Replace current sales badge class with added classes. $sales_flash = str_replace( 'class="onsale"', 'class="onsale ' . esc_attr( $classes ) . '"', $sales_flash ); return $sales_flash; } add_filter( 'woocommerce_sale_flash', 'bs4_wc_sale_flash' ); /** * Make single product variation select fields Bootstrap friendly. * * @param array $args Select field arguments. */ function bs4_wc_dropdown_variation_attribute_options_args( $args ) { $args['class'] = 'form-control form-control-sm'; return $args; } add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'bs4_wc_dropdown_variation_attribute_options_args' ); /** * Make single product variation select field reset link Bootstrap friendly. * * @param array $html Reset variations link HTML. */ function bs4_wc_reset_variations_link( $html ) { $html = str_replace( 'class="reset_variations"', 'class="reset_variations form-text small"', $html ); return $html; } add_filter( 'woocommerce_reset_variations_link', 'bs4_wc_reset_variations_link' ); /** * Make WooCommerce breadcrumbs Bootstrap 4 friendly. * * @link https://docs.woocommerce.com/document/customise-the-woocommerce-breadcrumb/ * * @param array $args Breadcrumb with new args. */ function bs4_filter_default_wc_breadcrumbs( $args ) { // Set new breadcrumb settings. $args = array( 'delimiter' => ' ', 'wrap_before' => '', 'before' => '', 'home' => _x( 'Home', 'breadcrumb', 'bs4' ), ); return $args; } add_filter( 'woocommerce_breadcrumb_defaults', 'bs4_filter_default_wc_breadcrumbs' ); /** * Make WooCommerce sales badge a Bootstrap 4 badge. * * @link https://docs.woocommerce.com/document/editing-product-data-tabs/ * * @param string $tab_title Title for Reviews tab. */ function bs4_wc_reviews_tab_badge( $tab_title ) { global $product; // Get review count to use in badge. $reviews_count = $product->get_review_count(); $badge_class = get_theme_mod( 'wc_sales_badge_color', 'primary' ); $classes = ''; if ( $badge_class && 'none' !== $badge_class ) { $badge_class = 'bg-' . sanitize_html_class( $badge_class ); $classes = join( ' ', bs4_get_badge_class( $badge_class ) ); } return sprintf( '%s %s', __( 'Reviews', 'bs4' ), esc_attr( $classes ), $reviews_count ); } add_filter( 'woocommerce_product_reviews_tab_title', 'bs4_wc_reviews_tab_badge' ); /** * Make links in WooCommerce notices Bootstrap alert links. * * @param string $message Notice message. */ function bs4_wc_filter_notice_link( $message ) { $message = str_replace( 'class="showlogin"', 'class="showlogin alert-link"', $message ); $message = str_replace( 'class="showcoupon"', 'class="showcoupon alert-link"', $message ); return $message; } add_filter( 'woocommerce_add_notice', 'bs4_wc_filter_notice_link' ); add_filter( 'woocommerce_add_success', 'bs4_wc_filter_notice_link' ); add_filter( 'woocommerce_add_error', 'bs4_wc_filter_notice_link' ); /** * Make loop product add to cart link Bootstrap friendly. */ function bs4_wc_loop_add_to_cart_link() { global $product; return sprintf( '%s', esc_url( $product->add_to_cart_url() ), esc_attr( isset( $quantity ) ? $quantity : 1 ), esc_attr( $product->get_id() ), esc_attr( $product->get_sku() ), esc_attr( 'button card-link' ), esc_html( $product->add_to_cart_text() ) ); } add_filter( 'woocommerce_loop_add_to_cart_link', 'bs4_wc_loop_add_to_cart_link' ); /** * Make cart remove link Bootstrap and HTML5 friendly. * * @param string $html Cart remove product link. */ function bs4_wc_cart_item_remove_link( $html ) { $html = str_replace( 'class="remove"', 'class="remove close"', $html ); $html = str_replace( '>×', '>', $html ); return $html; } add_filter( 'woocommerce_cart_item_remove_link', 'bs4_wc_cart_item_remove_link' );