/
var
/
www
/
barefootlaw.org
/
wp-content
/
themes
/
barefoot
/
inc
/
woocommerce
/
Upload File
HOME
<?php /** * Custom WooCommerce Template Tags & Settings for Theme * * Eventually, some of the functionality here could be replaced by WooCommerce core features. * * @package Aisconverse * @subpackage Covercase * @since Covercase 1.0 */ $basement_sidebar = ''; /** * WooCommerce Setup */ require( get_theme_file_path( 'inc/woocommerce/functions/setup.php' ) ); /** * Overridden and filtered sections */ require( get_theme_file_path( 'inc/woocommerce/functions/ob-buffers.php' ) ); if ( ! function_exists( 'covercase_woo_output_woo_page_title' ) ) { /** * Output Default Page Title for Meta pages * * @since Covercase 1.0 */ function covercase_woo_output_woo_page_title() { woocommerce_page_title(); } add_action( 'covercase_woo_page_title', 'covercase_woo_output_woo_page_title' ); } if ( ! function_exists( 'covercase_woo_output_breadcrumbs' ) ) { /** * Output WooCommerce Breadcrumbs * * @since Covercase 1.0 */ function covercase_woo_output_breadcrumbs() { if ( is_cart() || is_checkout() || ( is_account_page() && is_user_logged_in() ) ) { get_template_part( 'template-parts/page-title/breadcrumbs' ); } } add_action( 'covercase_woo_breadcrumbs', 'covercase_woo_output_breadcrumbs' ); } if ( ! function_exists( 'covercase_woo_sidebar_settings' ) ) { /** * Custom Sidebar Settings For WooCommerce Pages * * @since Covercase 1.0 */ function covercase_woo_sidebar_settings( $settings ) { if ( is_cart() || is_checkout() || is_singular( 'product' ) || is_account_page() ) { $settings['sidebar'] = 'no'; } return $settings; } add_filter( 'basement_sidebar_settings', 'covercase_woo_sidebar_settings' ); } if ( ! function_exists( 'covercase_woo_output_woo_sub_page_title' ) ) { /** * Output Default Sub Title for Meta pages * * @since Covercase 1.0 */ function covercase_woo_output_woo_sub_page_title() { $title_woo_meta_page = ''; if ( is_product_category() ) { $title_woo_meta_page = __( 'Product Category', 'covercase' ); } elseif ( is_product_tag() ) { $title_woo_meta_page = __( 'Product Tag', 'covercase' ); } if ( $title_woo_meta_page ) { ?> <div class="breadcrumb-block"> <ol class="breadcrumb"> <li class="breadcrumb-item"><span><span><?php echo esc_html( $title_woo_meta_page ); ?></span></span></li> </ol> </div> <?php } } add_action( 'covercase_woo_sub_page_title', 'covercase_woo_output_woo_sub_page_title' ); } //Override default wrapper tags remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); if ( ! function_exists( 'covercase_woo_products_loop' ) ) { /** * Output information about products * * @since Covercase 1.0 */ function covercase_woo_products_loop() { // Init custom product loop $loop_products = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => - 1 ) ); $total_products = 0; if ( $loop_products->have_posts() ) { while ( $loop_products->have_posts() ) : $loop_products->the_post(); global $product; if ( empty( $product ) || ! $product->is_visible() ) { continue; } $total_products++; endwhile; } wp_reset_postdata(); return array( 'total' => $total_products ); } } if ( ! function_exists( 'covercase_woo_result_count' ) ) { /** * Output the result count text (Showing x - x of x results) for custom pages * * @since Covercase 1.0 */ function covercase_woo_result_count( $query ) { // Get all custom products info $products_info = covercase_woo_products_loop(); $total = isset( $products_info['total'] ) ? $products_info['total'] : ''; $per_page = isset( $query->query_vars['posts_per_page'] ) ? $query->query_vars['posts_per_page'] : 0; $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; $args = array( 'total' => $total, 'per_page' => $per_page, 'current' => $current, ); wc_get_template( 'loop/result-count.php', $args ); } } if ( ! function_exists( 'covercase_woo_output_content_wrapper' ) ) { /** * Change wrapper WooCommerce open tags * * @since Covercase 1.0 */ function covercase_woo_output_content_wrapper( $params ) { global $wp_registered_sidebars, $basement_sidebar; // Check if custom template loop or default WooCommerce archive loop $loop_products = isset( $params['loop_products'] ) ? $params['loop_products'] : ''; // Get template name $template_name = basement_get_template_name(); do_action( 'basement_before_wrap_content' ); $container_size = 'container'; if ( strpos( $template_name, 'fullwidth' ) !== false ) { $container_size = 'container-fluid'; } elseif ( strpos( $template_name, 'wide' ) !== false ) { $container_size = 'container-wide'; } $basement_sidebar = 'footer'; ?> <div class="content"> <!-- CONTAINER --> <div class="<?php echo esc_attr( $container_size ); ?>"> <?php if ( is_page() ) { // Start the Loop. while ( have_posts() ) : the_post(); $content = get_the_content(); if ( trim( $content ) !== '' ) { ?> <section class="content-woo"><?php the_content(); ?></section> <?php } endwhile; } elseif ( is_archive() ) { // Get WooCommerce content description ob_start(); woocommerce_taxonomy_archive_description(); woocommerce_product_archive_description(); $desc = ob_get_clean(); if ( trim( $desc ) !== '' ) { echo '<section class="content-woo">'.$desc.'</section>'; } } ?> <?php if ( ! is_singular( 'product' ) ) { ?> <div class="row products-top-bar"> <?php if ( ! empty( $loop_products ) ) { // Get Sidebar For Custom Shop Grid $filter_sidebar = get_option( 'basement_framework_woo_sidebar_page_filter' ); $filter_status = is_active_sidebar( $filter_sidebar ); ?> <div class="col-lg-7 order-lg-7 text-center text-lg-right"> <div class="woo-filter-controls"> <?php covercase_woo_result_count( $loop_products ); ?> </div> </div> <div class="col-lg-5 order-lg-5 text-center text-lg-left"> <?php if ( $filter_status ) { ?> <div class="products-top-bar__filter"> <a href="#js-filters" class="products-top-bar__filtrate" id="js-filter-toggle" title="<?php esc_attr_e( 'Catalog Filters', 'covercase' ); ?>"><i class="cov-filter" aria-hidden="true"></i> <?php _e( 'Catalog Filters', 'covercase' ); ?> </a> </div> <?php } ?> </div> <?php } else { // Get Sidebar For Shop Grid $filter_sidebar = get_option( 'basement_framework_woo_sidebar_filter' ); $filter_status = is_active_sidebar( $filter_sidebar ); ?> <div class="col-lg-7 order-lg-7 text-center text-lg-right"> <div class="woo-filter-controls"> <?php woocommerce_catalog_ordering(); ?> <?php woocommerce_result_count(); ?> </div> </div> <div class="col-lg-5 order-lg-5 text-center text-lg-left"> <?php if ( $filter_status ) { ?> <div class="products-top-bar__filter"> <a href="#js-filters" class="products-top-bar__filtrate" id="js-filter-toggle" title="<?php esc_attr_e( 'Catalog Filters', 'covercase' ); ?>"><i class="cov-filter" aria-hidden="true"></i> <?php _e( 'Catalog Filters', 'covercase' ); ?> </a> <?php covercase_woo_active_filters(); ?> </div> <?php } ?> </div> <?php } ?> <?php if ( $filter_status && ! empty( $wp_registered_sidebars ) ) { ?> <div class="products-top-bar__catalog-filters" id="js-filters"> <i class="products-top-bar-bg"></i> <div class="filter-footer footer footer_yes footer_line_no footer_style_dark footer_animation_disable footer_animation_bounce scope_public footer_type_woo"> <div class="footer-row"> <div class="<?php echo esc_attr( $container_size ); ?>"> <div class="row footer-widget-row"> <?php dynamic_sidebar( $filter_sidebar ) ?> </div> </div> </div> </div> </div> <?php } ?> </div> <?php } ?> <div class="row"> <?php /** * basement_before_content basement framework hook. * * @hooked basement_output_left_sidebar - 20 (outputs left sidebar) * @hooked basement_output_content_wrapper - 21 (outputs opening divs for the content) * * @package Aisconverse * @subpackage Covercase * @since Covercase 1.0 */ do_action( 'basement_before_content' ); } add_action( 'woocommerce_before_main_content', 'covercase_woo_output_content_wrapper', 11 ); } if ( ! function_exists( 'covercase_woo_get_current_page_url' ) ) { /** * Displays current page URL * * @since Covercase 1.0 */ function covercase_woo_get_current_page_url() { if ( defined( 'SHOP_IS_ON_FRONT' ) ) { $link = home_url(); } elseif ( is_shop() ) { $link = get_permalink( wc_get_page_id( 'shop' ) ); } elseif ( is_product_category() ) { $link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' ); } elseif ( is_product_tag() ) { $link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' ); } else { $queried_object = get_queried_object(); $link = get_term_link( $queried_object->slug, $queried_object->taxonomy ); } // Min/Max. if ( isset( $_GET['min_price'] ) ) { $link = add_query_arg( 'min_price', wc_clean( wp_unslash( $_GET['min_price'] ) ), $link ); } if ( isset( $_GET['max_price'] ) ) { $link = add_query_arg( 'max_price', wc_clean( wp_unslash( $_GET['max_price'] ) ), $link ); } // Order by. if ( isset( $_GET['orderby'] ) ) { $link = add_query_arg( 'orderby', wc_clean( wp_unslash( $_GET['orderby'] ) ), $link ); } /** * Search Arg. * To support quote characters, first they are decoded from " entities, then URL encoded. */ if ( get_search_query() ) { $link = add_query_arg( 's', rawurlencode( wp_specialchars_decode( get_search_query() ) ), $link ); } // Post Type Arg. if ( isset( $_GET['post_type'] ) ) { $link = add_query_arg( 'post_type', wc_clean( wp_unslash( $_GET['post_type'] ) ), $link ); } // Min Rating Arg. if ( isset( $_GET['rating_filter'] ) ) { $link = add_query_arg( 'rating_filter', wc_clean( wp_unslash( $_GET['rating_filter'] ) ), $link ); } // All current filters. if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) { foreach ( $_chosen_attributes as $name => $data ) { $filter_name = sanitize_title( str_replace( 'pa_', '', $name ) ); if ( ! empty( $data['terms'] ) ) { $link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link ); } if ( 'or' == $data['query_type'] ) { $link = add_query_arg( 'query_type_' . $filter_name, 'or', $link ); } } } return $link; } } if ( ! function_exists( 'covercase_woo_active_filters' ) ) { /** * Displays all active filters * * @since Covercase 1.0 */ function covercase_woo_active_filters() { $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $min_price = isset( $_GET['min_price'] ) ? wc_clean( $_GET['min_price'] ) : 0; $max_price = isset( $_GET['max_price'] ) ? wc_clean( $_GET['max_price'] ) : 0; $rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) ) : array(); $base_link = covercase_woo_get_current_page_url(); if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price || ! empty( $rating_filter ) ) { echo '<div class="products-top-bar__filters">'; // Attributes if ( ! empty( $_chosen_attributes ) ) { foreach ( $_chosen_attributes as $taxonomy => $data ) { foreach ( $data['terms'] as $term_slug ) { if ( ! $term = get_term_by( 'slug', $term_slug, $taxonomy ) ) { continue; } $filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) ); $current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( $_GET[ $filter_name ] ) ) : array(); $current_filter = array_map( 'sanitize_title', $current_filter ); $new_filter = array_diff( $current_filter, array( $term_slug ) ); $link = remove_query_arg( array( 'add-to-cart', $filter_name ), $base_link ); if ( sizeof( $new_filter ) > 0 ) { $link = add_query_arg( $filter_name, implode( ',', $new_filter ), $link ); } echo '<a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'covercase' ) . '" href="' . esc_url( $link ) . '"><i class="cov-pm-close" aria-hidden="true"></i>' . esc_html( $term->name ) . '</a>'; } } } if ( $min_price ) { $link = remove_query_arg( 'min_price', $base_link ); echo '<a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'covercase' ) . '" href="' . esc_url( $link ) . '"><i class="cov-pm-close" aria-hidden="true"></i>' . sprintf( __( 'Min %s', 'covercase' ), wc_price( $min_price ) ) . '</a>'; } if ( $max_price ) { $link = remove_query_arg( 'max_price', $base_link ); echo '<a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'covercase' ) . '" href="' . esc_url( $link ) . '"><i class="cov-pm-close" aria-hidden="true"></i>' . sprintf( __( 'Max %s', 'covercase' ), wc_price( $max_price ) ) . '</a>'; } if ( ! empty( $rating_filter ) ) { foreach ( $rating_filter as $rating ) { $link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) ); $link = $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter', $base_link ); echo '<a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'covercase' ) . '" href="' . esc_url( $link ) . '"><i class="cov-pm-close" aria-hidden="true"></i>' . sprintf( esc_html__( 'Rated %s out of 5', 'covercase' ), esc_html( $rating ) ) . '</a>'; } } echo '</div>'; } } } if ( ! function_exists( 'covercase_woo_output_content_wrapper_end' ) ) { /** * Change wrapper WooCommerce close tags * * @since Covercase 1.0 */ function covercase_woo_output_content_wrapper_end() { /** * basement_after_content basement framework hook. * * @hooked basement_output_content_wrapper_end - 19 (outputs closing divs for the content) * @hooked basement_output_right_sidebar - 20 (outputs right sidebar) * * @package Aisconverse * @subpackage Covercase * @since Covercase 1.0 */ do_action( 'basement_after_content' ); ?> </div> </div> <!-- /.container --> </div> <?php do_action( 'basement_after_wrap_content' ); } add_action( 'woocommerce_after_main_content', 'covercase_woo_output_content_wrapper_end', 11 ); } // Disable top bar functionality remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); // Disable default no product found message remove_action( 'woocommerce_no_products_found', 'wc_no_products_found' ); if ( ! function_exists( 'covercase_woo_no_products_found' ) ) { /** * Custom WooCommerce pagination * * @since Covercase 1.0 */ function covercase_woo_no_products_found() { ?> <article class="no-results not-found search-item text-center col-12 woocommerce-info"><?php _e( 'No products were found matching your selection.', 'covercase' ); ?></article> <?php } add_action( 'woocommerce_no_products_found', 'covercase_woo_no_products_found', 10 ); } // Disable & Override default pagination remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination' ); if ( ! function_exists( 'covercase_woo_pagination' ) ) { /** * Custom WooCommerce pagination * * @since Covercase 1.0 */ function covercase_woo_pagination( $params ) { // Check if custom template loop or default WooCommerce archive loop $loop_products = isset( $params['loop_products'] ) ? $params['loop_products'] : ''; if ( ! empty( $loop_products ) ) { global $wp_rewrite; $total = isset( $loop_products->max_num_pages ) ? $loop_products->max_num_pages : 0; $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; $base = html_entity_decode( get_pagenum_link() ); $query_args = array(); $url_parts = explode( '?', $base ); if ( isset( $url_parts[1] ) ) { wp_parse_str( $url_parts[1], $query_args ); } $base = remove_query_arg( array_keys( $query_args ), $base ); $base = trailingslashit( $base ) . '%_%'; $format = $wp_rewrite->using_index_permalinks() && ! strpos( $base, 'index.php' ) ? 'index.php/' : ''; $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; } else { if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) { return; } $args = array( 'total' => wc_get_loop_prop( 'total_pages' ), 'current' => wc_get_loop_prop( 'current_page' ), ); if ( wc_get_loop_prop( 'is_shortcode' ) ) { $args['base'] = esc_url_raw( add_query_arg( 'product-page', '%#%', false ) ); $args['format'] = '?product-page = %#%'; } else { $args['base'] = esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ); $args['format'] = ''; } $total = isset( $args['total'] ) ? $args['total'] : wc_get_loop_prop( 'total_pages' ); $current = isset( $args['current'] ) ? $args['current'] : wc_get_loop_prop( 'current_page' ); $base = isset( $args['base'] ) ? $args['base'] : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ); $format = isset( $args['format'] ) ? $args['format'] : ''; } if ( $total <= 1 ) { return; } $current = max( 1, $current ); // Set up paginated links. $links = paginate_links( apply_filters( 'woocommerce_pagination_args', array( // WPCS: XSS ok. 'base' => $base, 'format' => $format, 'add_args' => false, 'current' => $current, 'total' => $total, 'end_size' => 3, 'mid_size' => 3, 'type' => 'array', 'prev_text' => '<i class="cov-arrow-bl-l" aria-hidden="true"></i>', 'next_text' => '<i class="cov-arrow-bl-r" aria-hidden="true"></i>', ) ) ); $paginate = ''; $style = 'default'; if ( $links ) { if ( $style === 'default' ) { $cross_class = ''; $arrow_prev = ''; $arrow_next = ''; if ( $total == $current && $current != 1 && $total != 1 ) { $cross_class = 'page-pagination--last'; $arrow_prev = '<div><a class="next page-numbers" href="#"><i class="cov-arrow-bl-r" aria-hidden="true"></i></a></div>'; } elseif ( $current == 1 && $current < $total ) { $cross_class = 'page-pagination--first'; $arrow_next = '<div><a class="prev page-numbers" href="#"><i class="cov-arrow-bl-l" aria-hidden="true"></i></a></div>'; } echo '<!-- PAGINATION -->'; $paginate .= '<div class="products-pagination page-pagination ' . $cross_class . '" aria-label="' . __( 'Pagination', 'covercase' ) . '">' . $arrow_next . '<div>'; $paginate .= implode( '</div><div>', $links ); $paginate .= '</div>' . $arrow_prev . '</div>'; printf( '%s', $paginate ); echo '<!-- /.pagination -->'; } } } add_action( 'woocommerce_after_shop_loop', 'covercase_woo_pagination' ); } $product_counter = 0; if ( ! function_exists( 'covercase_woo_product_loop_start' ) ) { /** * Change default product loop (start) replace <ul> -> <div> tag * * @since Covercase 1.0 */ function covercase_woo_product_loop_start( $html ) { $template_name = basement_get_template_name(); do_action( 'basement_before_wrap_content' ); $container_id = ''; $container_class = ''; if ( strpos( $template_name, 'mixed' ) !== false ) { $container_id = 'id="js-products-mixed"'; $container_class = 'products--mixed'; } $wrapper = ''; if ( is_product() || is_cart() ) { $arrows = '<a href="#" class="products-single-wrapper__arrow products-single-wrapper__arrow--prev" title="'.__('Previous','covercase').'"><i class="cov-arrow-bl-l" aria-hidden="true"></i></a>'; $arrows .= '<a href="#" class="products-single-wrapper__arrow products-single-wrapper__arrow--next" title="'.__('Next','covercase').'"><i class="cov-arrow-bl-r" aria-hidden="true"></i></a>'; $wrapper = '<!-- PRODUCT SINGLE WRAPPER --><div class="products-single-wrapper">' . $arrows; } return preg_replace( '/<ul class="/im', $wrapper . '<div ' . $container_id . ' class="' . $container_class . ' row ', $html ); } add_filter( 'woocommerce_product_loop_start', 'covercase_woo_product_loop_start' ); } if ( ! function_exists( 'covercase_woo_product_loop_end' ) ) { /** * Change default product loop (end) replace </ul> -> </div> tag * * @since Covercase 1.0 */ function covercase_woo_product_loop_end( $html ) { $wrapper = ''; if ( is_product() || is_cart() ) { $pagination = '<div class="products-single-wrapper__pagination js-products-single-wrapper-pagination"></div>'; $wrapper = $pagination . '</div><!-- /.product-single-wrapper -->'; } return preg_replace( '/<\/ul>/im', '</div>' . $wrapper, $html ); } add_filter( 'woocommerce_product_loop_end', 'covercase_woo_product_loop_end' ); } if ( ! function_exists( 'covercase_woo_single_product_archive_thumbnail_size' ) ) { /** * New thumbnail default size * * @since Covercase 1.0 */ function covercase_woo_single_product_archive_thumbnail_size() { return 'full'; } add_filter( 'single_product_archive_thumbnail_size', 'covercase_woo_single_product_archive_thumbnail_size' ); } // Reset product card functionality remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open' ); remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash' ); remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail' ); remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title' ); remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); if ( ! function_exists( 'woocommerce_get_product_thumbnail_src' ) ) { /** * Help function for return thumbnail src * * @since Covercase 1.0 */ function woocommerce_get_product_thumbnail_src( $size = 'woocommerce_thumbnail', $placeholder = true ) { global $product; $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size ); if ( has_post_thumbnail( $product->get_id() ) ) { $image = get_the_post_thumbnail_url( $product->get_id(), $image_size ); } elseif ( ( $parent_id = wp_get_post_parent_id( $product->get_id() ) ) && has_post_thumbnail( $parent_id ) ) { $image = get_the_post_thumbnail_url( $parent_id, $image_size ); } elseif ( $placeholder ) { $image = wc_placeholder_img_src(); } else { $image = ''; } return $image; } } if ( ! function_exists( 'covercase_woo_loop_add_to_cart_link' ) ) { /** * Change default `Add to cart` link to icon in loop while * * @since Covercase 1.0 */ function covercase_woo_loop_add_to_cart_link( $link ) { return preg_replace( array( '/class="/im', '/>.*?</im', '/(title|aria-label)=".*?"/im' ), array( 'class="js-product-action-trigger ', '><i class="cov-shopping-cart" aria-hidden="true"></i><', '$1="' . __( 'Add to Cart', 'covercase' ) . '"' ), $link ); } add_filter( 'woocommerce_loop_add_to_cart_link', 'covercase_woo_loop_add_to_cart_link' ); } if ( ! function_exists( 'covercase_woo_products_general_settings' ) ) { /** * Uncheck AJAX add to cart functionality * * @since Covercase 1.0 */ function covercase_woo_products_general_settings( $settings ) { // Disable AJAX add to cart if ( isset( $settings['3']['id'] ) && $settings['3']['id'] === 'woocommerce_enable_ajax_add_to_cart' ) { $settings['3']['default'] = 'no'; } return $settings; } add_filter( 'woocommerce_products_general_settings', 'covercase_woo_products_general_settings' ); } if ( ! function_exists( 'covercase_woo_product_supports' ) ) { /** * HARD RESET AJAX add to cart functionality * * @since Covercase 1.0 */ function covercase_woo_product_supports( $status, $feature, $product ) { if ( 'ajax_add_to_cart' === $feature ) { $status = false; } return $status; } add_filter( 'woocommerce_product_supports', 'covercase_woo_product_supports', 10, 3 ); } if ( ! function_exists( 'covercase_woo_wc_print_notices' ) ) { /** * Prints messages and errors which are stored in the session, then clears them. * * @since Covercase 1.0 */ function covercase_woo_wc_print_notices() { ?> <!-- WooCommerce Message Template --> <div class="d-none" id="js-woo-message-template"> <div class="woo-messages-popup woo-messages-popup--%type%"> <a href="#" class="woo-message-hide js-woo-message-hide"><i class="cov-pm-close" aria-hidden="true"></i></a> <div class="woo-message-entry-icon"><i></i></div> %html% </div> </div> <!-- /.WooCommerce Message Template --> <div class="woo-messages-popups-list" id="js-woo-messages"></div> <!-- WooCommerce Cart Slide Modal --> <div class="woo-page-modal__back" id="js-woo-quick-cart-back"></div> <div class="woo-page-modal" id="js-woo-quick-cart"> <div class="woo-page-modal__wrapper"> <div class="woo-page-modal__body"> <a href="#" class="woo-page-modal__close" id="js-woo-quick-cart-close" title="<?php esc_attr_e( 'Close', 'covercase' ); ?>"><i class="cov-pm-close" aria-hidden="true"></i></a> <div class="woo-page-modal__header"><?php _e( 'Shopping Cart', 'covercase' ); ?></div> <?php // Insert cart widget placeholder - code in woocommerce.js will update this on page load echo '<div class="widget_shopping_cart_content"></div>'; ?> </div> </div> </div> <!-- /.WooCommerce Slide Modal --> <?php } add_action( 'basement_before_wrapper', 'covercase_woo_wc_print_notices', 11 ); } if ( ! function_exists( 'covercase_woo_get_price_html' ) ) { /** * Adds price wrap block * * @since Covercase 1.0 */ function covercase_woo_get_price_html( $price, $product ) { return '<span class="price-body">' . $price . '</span><i></i>'; } add_filter( 'woocommerce_get_price_html', 'covercase_woo_get_price_html', 15, 2 ); } if ( ! function_exists( 'covercase_woo_output_cart_header' ) ) { /** * Outputs cart fragment in Header * * @since Covercase 1.0 */ function covercase_woo_output_cart_header( $nav_classes ) { ?> <div class="<?php echo implode( ' ', $nav_classes ); ?>"> <a href="<?php echo esc_url( wc_get_cart_url() ); ?>" id="js-woo-cart-toggle" title="<?php esc_attr_e( 'View cart', 'covercase' ); ?>"> <i class="cov-shopping-cart" aria-hidden="true"></i> <sup class="woo-cart-counter"><?php echo WC()->cart->get_cart_contents_count(); ?></sup> </a> </div> <?php } add_action( 'covercase_woo_cart_header', 'covercase_woo_output_cart_header' ); } if ( ! function_exists( 'covercase_woo_cart_count_update' ) ) { function covercase_woo_cart_count_update( $fragments ) { ob_start(); ?> <sup class="woo-cart-counter"><?php echo WC()->cart->get_cart_contents_count(); ?></sup> <?php $html = ob_get_clean(); $fragments['sup.woo-cart-counter'] = $html; return $fragments; } add_filter( 'add_to_cart_fragments', 'covercase_woo_cart_count_update' ); } // Remove Widget cart buttons remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 ); remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 ); if ( ! function_exists( 'covercase_woo_widget_shopping_cart_button_view_cart' ) ) { /** * Output the view cart button. * * @since Covercase 1.0 */ function covercase_woo_widget_shopping_cart_button_view_cart() { echo '<a href="' . esc_url( wc_get_cart_url() ) . '" class="button btn-cart wc-forward">' . esc_html__( 'Cart', 'covercase' ) . '</a>'; } add_action( 'woocommerce_widget_shopping_cart_buttons', 'covercase_woo_widget_shopping_cart_button_view_cart', 10 ); } if ( ! function_exists( 'covercase_woo_widget_shopping_cart_proceed_to_checkout' ) ) { /** * Output the proceed to checkout button. * * @since Covercase 1.0 */ function covercase_woo_widget_shopping_cart_proceed_to_checkout() { echo '<a href="' . esc_url( wc_get_checkout_url() ) . '" class="button btn-checkout wc-forward">' . esc_html__( 'Checkout', 'covercase' ) . '</a>'; } add_action( 'woocommerce_widget_shopping_cart_buttons', 'covercase_woo_widget_shopping_cart_proceed_to_checkout', 20 ); } if ( ! function_exists( 'covercase_woo_get_product_search_form' ) ) { /** * Filtrate Default Product Search form * * @since Covercase 1.0 */ function covercase_woo_get_product_search_form( $form ) { $html = ''; $html .= '<form role="search" method="get" class="search-form woocommerce-product-search" action="' . esc_url( home_url( '/' ) ) . '">'; $html .= '<div class="search-form__body"><label>'; $html .= '<span class="screen-reader-text">' . __( 'Search for:', 'covercase' ) . '</span>'; $html .= '<input type="search" class="search-form__field" placeholder="' . esc_attr__( 'Search products…', 'covercase' ) . '" value="' . get_search_query() . '" name="s" />'; $html .= '</label><div class="search-submit-icon"><i aria-hidden="true" class="cov-search"></i></div></div>'; $html .= '<button type="submit">' . __( 'Search', 'covercase' ) . '</button><input type="hidden" name="post_type" value="product" />'; $html .= '</form>'; return $html; } add_filter( 'get_product_search_form', 'covercase_woo_get_product_search_form' ); } if ( ! function_exists( 'covercase_woo_override_widgets' ) ) { /** * Override default WooCommerce Widgets * * @since Covercase 1.0 */ function covercase_woo_override_widgets() { $widgets = array( 'WC_Widget_Recent_Reviews' => array( 'file' => 'inc/woocommerce/class-wc-widget-recent-reviews.php', 'class' => 'Covercase_WC_Widget_Recent_Reviews' ) ); if ( ! empty( $widgets ) ) { foreach ( $widgets as $widget_woo => $widget_theme ) { if ( class_exists( $widget_woo ) && file_exists( get_theme_file_path( $widget_theme['file'] ) ) ) { unregister_widget( $widget_woo ); require get_theme_file_path( $widget_theme['file'] ); register_widget( $widget_theme['class'] ); } } } } add_action( 'widgets_init', 'covercase_woo_override_widgets', 15 ); } // Remove current Empty cart message remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 ); if ( ! function_exists( 'covercase_woo_empty_cart_message' ) ) { /** * New empty cart message * * @since Covercase 1.0 */ function covercase_woo_empty_cart_message() { echo '<p class="cart-empty">' . wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your shopping cart is currently empty.<br>Please, continue shopping by returning to the shop.', 'covercase' ) ) ) . '</p>'; } add_action( 'woocommerce_cart_is_empty', 'covercase_woo_empty_cart_message' ); } if ( ! function_exists( 'covercase_woo_form_field_args' ) ) { /** * Reorder Checkout form fields * * @since Covercase 1.0 */ function covercase_woo_form_field_args( $args, $key, $value ) { $placeholder = isset( $args['label'] ) ? $args['label'] : ''; $id = isset( $args['id'] ) ? $args['id'] : ''; $args['label'] = ''; $args['placeholder'] = $placeholder; switch ( $id ) { case 'billing_first_name' : case 'billing_last_name' : case 'shipping_first_name': case 'shipping_last_name': case 'billing_address_1' : case 'billing_address_2' : case 'billing_state' : case 'billing_postcode' : $args['class'][] = 'col-md-6'; break; default : $args['class'][] = 'col-12'; break; } if ( $args['required'] ) { $args['custom_attributes'] = array('required'=>'required'); } return $args; } add_filter( 'woocommerce_form_field_args', 'covercase_woo_form_field_args', 10, 3 ); } if ( ! function_exists( 'covercase_woo_default_address_fields' ) ) { /** * Update placeholder value for address2 field * * @since Covercase 1.0 */ function covercase_woo_default_address_fields( $fields ) { $fields['address_2']['placeholder'] = __( 'Apartment, suite etc. (optional)', 'covercase' ); return $fields; } add_filter( 'woocommerce_default_address_fields', 'covercase_woo_default_address_fields' ); } if ( ! function_exists( 'covercase_woo_checkout_coupon_form' ) ) { /** * Hide coupon form for cart page * * @since Covercase 1.0 */ function covercase_woo_checkout_coupon_form() { echo '<form class="js-checkout_coupon" method="post" style="display:none"></form>'; } add_action( 'woocommerce_before_checkout_form', 'covercase_woo_checkout_coupon_form' ); } if ( ! function_exists( 'covercase_woo_notice' ) ) { /** * Disable Account form on checkout page form * * @since Covercase 1.0 */ function covercase_woo_notice( $message ) { $message = preg_replace( '/#"\s+class="showlogin"/im', wc_get_page_permalink( 'myaccount' ) . '" target="_blank" ', $message ); return $message; } add_filter( 'woocommerce_add_notice', 'covercase_woo_notice' ); } if ( ! function_exists( 'covercase_woo_display_item_meta' ) ) { /** * Display custom item meta data. * * @since Covercase 1.0 */ function covercase_woo_display_item_meta( $item, $args = array() ) { $args = wp_parse_args( $args, array( 'before' => '<dl class="wc-item-meta"><li>', 'after' => '</li></dl>', 'separator' => '</li><li>', 'echo' => true, 'autop' => false, ) ); echo '<dl class="variation">'; foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) { $value = $args['autop'] ? wp_kses_post( $meta->display_value ) : wp_kses_post( make_clickable( trim( $meta->display_value ) ) ); $strings = wp_kses_post( $meta->display_key ); ?> <dt class="variation-color"><?php printf( '%s', $strings ); ?>:</dt> <dd class="variation-color"><?php printf( '%s', $value ); ?></dd> <?php } echo '</dl>'; } } if ( ! function_exists( 'covercase_woo_gallery_img_size' ) ) { /** * Full images on single products pages * * @since Covercase 1.0 */ function covercase_woo_gallery_img_size() { return 'full'; } add_filter( 'woocommerce_gallery_image_size', 'covercase_woo_gallery_img_size' ); add_filter( 'woocommerce_gallery_full_size', 'covercase_woo_gallery_img_size' ); add_filter( 'woocommerce_gallery_thumbnail_size', 'covercase_woo_gallery_img_size' ); } if ( ! function_exists( 'covercase_woo_show_product_images' ) ) { /** * Output custom thumbnails on single product pages * * @since Covercase 1.0 */ function covercase_woo_show_product_images() { if ( ! function_exists( 'wc_get_gallery_image_html' ) ) { return; } global $product; $html = ''; $post_thumbnail_id = $product->get_image_id(); ?> <?php if ( has_post_thumbnail() ) { $html .= wc_get_gallery_image_html( $post_thumbnail_id ); } else { $html .= sprintf( '<li class="woo-product-gallery__image"><a href="#" title="%2$s"><img src="%1$s" alt="%2$s" class="wp-post-image" /></a></li>', esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'covercase' ) ); } ob_start(); echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, $post_thumbnail_id ); do_action( 'woocommerce_product_thumbnails' ); $thumbnails = ob_get_clean(); $thumbnails = preg_replace( array( '/srcset=".*?"/', '/sizes=".*?"/', '/data-large_image_width=".*?"/', '/data-large_image_height=".*?"/' ), '', $thumbnails ); echo str_replace( array( '<div', '/div>', 'woocommerce-product-gallery__image' ), array( '<li', '/li>', 'woo-product-gallery__image' ), $thumbnails ); } } // Move rating on single product after price remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating' ); if ( ! function_exists( 'covercase_woo_template_single_rating' ) ) { /** * New custom rating on single product page * * @since Covercase 1.0 */ function covercase_woo_template_single_rating() { global $product; if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) { return; } $rating_count = $product->get_rating_count(); $review_count = $product->get_review_count(); $average = $product->get_average_rating(); if ( $rating_count > 0 ) { ?> <div class="woocommerce-product-rating"> <div class="woocommerce-product-rating__table"> <div class="woocommerce-product-rating__row"> <div class="woocommerce-product-rating__cell"><?php if ( comments_open() ) : ?><a href="#reviews" class="woocommerce-review-link" rel="nofollow"><?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'covercase' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?></a><?php endif ?></div> <div class="woocommerce-product-rating__cell text-right"><?php echo wc_get_rating_html( $average, $rating_count ); ?></div> </div> </div> </div> <?php } } add_action( 'woocommerce_single_product_summary', 'covercase_woo_template_single_rating', 11 ); } if ( ! function_exists( 'covercase_woo_after_add_to_cart_button' ) ) { /** * Sharing on single product page * * @since Covercase 1.0 */ function covercase_woo_after_add_to_cart_button() { $type = covercase_woo_get_product_type(); if ( function_exists( 'basement_post_share' ) && 'variable' !== $type ) { /** * Displays Share Block For Single Product * * @package Aisconverse * @subpackage Covercase * @since Covercase 1.0 */ basement_post_share( true, 'dropdown', true ); } } add_action( 'woocommerce_after_add_to_cart_button', 'covercase_woo_after_add_to_cart_button' ); } // Remove sharing -> replace to basement Yandex sharing remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 ); // Move meta remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 ); if ( ! function_exists( 'covercase_woo_template_single_meta' ) ) { /** * Custom meta information on single product page * * @since Covercase 1.0 */ function covercase_woo_template_single_meta() { global $product; ?> <div class="product_meta"> <?php do_action( 'woocommerce_product_meta_start' ); ?> <?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?> <div class="sku_wrapper product_meta__row"> <div class="product_meta__cell"><?php esc_html_e( 'SKU:', 'covercase' ); ?></div> <?php $sku_final = ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'covercase' ) ?> <div class="sku product_meta__cell"><?php printf('%s', $sku_final); ?></div> </div> <?php endif; ?> <div class="posted_in product_meta__row"><?php echo wc_get_product_category_list( $product->get_id(), ', ', '<div class="product_meta__cell">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'covercase' ) . '</div><div class="product_meta__cell">', '</div>' ); ?></div> <div class="tagged_as product_meta__row"><?php echo wc_get_product_tag_list( $product->get_id(), ', ', '<div class="product_meta__cell">' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'covercase' ) . '</div><div class="product_meta__cell">', '</div>' ); ?></div> <?php do_action( 'woocommerce_product_meta_end' ); ?> </div> <?php } add_action( 'woocommerce_single_product_summary', 'covercase_woo_template_single_meta', 41 ); } // Remove default WooCommerce tabs from single product remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs' ); // Remove headings from tabs add_filter( 'woocommerce_product_description_heading', '__return_false' ); add_filter( 'woocommerce_product_additional_information_heading', '__return_false' ); if ( ! function_exists( 'covercase_woo_product_reviews_tab_title' ) ) { /** * Change review title tab * * @since Covercase 1.0 */ function covercase_woo_product_reviews_tab_title( $title, $key ) { return balanceTags( '<span>' . str_replace( array( '(', ')' ), array( '</span><sup>', '</sup>' ), $title ), true ); } add_filter( 'woocommerce_product_reviews_tab_title', 'covercase_woo_product_reviews_tab_title', 10, 2 ); } if ( ! function_exists( 'covercase_woo_product_review_comment_form_args' ) ) { /** * Change review form * * @since Covercase 1.0 */ function covercase_woo_product_review_comment_form_args( $comment_form ) { $commenter = wp_get_current_commenter(); $fieldset = $rating = ''; if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) { $rating = '<div class="comment-form-rating"><div class="raty-label">' . esc_html__( 'Your rating', 'covercase' ) . '</div><div class="raty-body"> <div class="raty"></div><input type="hidden" name="rating" id="raty-rating" value="1" required></div></div>'; } if ( is_user_logged_in() ) { $fieldset = '<div class="row row-raty"><div class="col-md-7"></div><div class="col-md-5 text-right">' . $rating . '</div></div> <div class="form-wrap">'; } $comment_form['fields'] = array( 'author' => '<div class="row wpcf7-form-control-wrap"><div class="col-sm-6">' . '<input id="author" name="author" placeholder="' . esc_attr__( 'Your name*', 'covercase' ) . '" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" required /></div>', 'email' => '<div class="col-sm-6">' . '<input id="email" name="email" placeholder="' . esc_attr__( 'Your email address*', 'covercase' ) . '" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-required="true" required /></div></div>' ); $comment_form['comment_field'] = $fieldset . '<div class="wpcf7-form-control-wrap"><textarea placeholder="' . esc_attr__( 'Review*', 'covercase' ) . '" id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></div></div>'; $comment_form['label_submit'] = esc_html__( 'Add a Review', 'covercase' ); $comment_form['class_form'] = 'comment-form wpcf7-form '; $comment_form['title_reply'] = __( 'Add your review', 'covercase' ); $comment_form['comment_notes_before'] = '<div class="row row-raty comment-notes"><div class="col-md-7"></div><div class="col-md-5 text-md-right">' . $rating . '</div></div>'; return $comment_form; } add_filter( 'woocommerce_product_review_comment_form_args', 'covercase_woo_product_review_comment_form_args' ); } if ( ! function_exists( 'covercase_woo_get_stock_html' ) ) { /** * Change stock settings form * * @since Covercase 1.0 */ function covercase_woo_get_stock_html( $html, $product ) { $availability = $product->get_availability(); $availability_class = isset( $availability['class'] ) ? $availability['class'] : ''; if ( ! empty( $html ) && 'out-of-stock' === $availability_class ) { if ( function_exists( 'basement_post_share' ) ) { /** * Displays Share Block For Single Product * * @package Aisconverse * @subpackage Covercase * @since Covercase 1.0 */ $html .= basement_post_share( false, 'dropdown', true ); } } return '<div class="woocommerce-product-stock">' . $html . '</div>'; } add_filter( 'woocommerce_get_stock_html', 'covercase_woo_get_stock_html', 10, 2 ); } if ( ! function_exists( 'covercase_woo_single_product_image_gallery_classes' ) ) { /** * Change default gallery classes for single product page * * @since Covercase 1.0 */ function covercase_woo_single_product_image_gallery_classes( $classes ) { $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 ); return array( 'woocommerce-product-gallery', 'woocommerce-product-gallery--' . ( has_post_thumbnail() ? 'with-images' : 'without-images' ), 'woocommerce-product-gallery--columns-' . absint( $columns ) ); } add_filter( 'woocommerce_single_product_image_gallery_classes', 'covercase_woo_single_product_image_gallery_classes' ); } if ( ! function_exists( 'covercase_woo_get_product_type' ) ) { /** * Get current product type * * @since Covercase 1.0 */ function covercase_woo_get_product_type( $product_id = null ) { global $product; if ( empty( $product_id ) ) { $product_id = absint( $product->get_id() ); } $post_type = get_post_type( $product_id ); if ( 'product_variation' === $post_type ) { return 'variation'; } elseif ( 'product' === $post_type ) { $terms = get_the_terms( $product_id, 'product_type' ); return ! empty( $terms ) ? sanitize_title( current( $terms )->name ) : 'simple'; } else { return false; } } } // Reset and move `Clear` link for Variable products add_filter( 'woocommerce_reset_variations_link', '__return_false' ); if ( ! function_exists( 'covercase_woo_before_add_to_cart_button' ) ) { /** * New place for clear link for variable selects * * @since Covercase 1.0 */ function covercase_woo_before_add_to_cart_button() { $type = covercase_woo_get_product_type(); if ( 'variable' === $type ) { echo '<a href="#" class="reset_variations" title="'.esc_attr__( 'Clean', 'covercase' ).'">' . esc_html__( 'Clean', 'covercase' ) . '</a>'; } } add_action( 'woocommerce_before_add_to_cart_button', 'covercase_woo_before_add_to_cart_button' ); }