>
>
>
'; } /** * WooCommerce markup after sidebar. * * @since 1.0.0 */ public function woocommerce_after_sidebar() { // This hook is documented in index.php. do_action( 'bayleaf_bottom_of_site_content', 'bottom_of_site_content' ); ?>
esc_html__( 'WooCommerce - Archive Filters', 'bayleaf' ), 'id' => 'wc-archive-filters', 'before_widget' => '
', ], ] ); } /** * Conditionally display sidebar on a wooCommerce page. * * @since 1.0.0 */ public function display_sidebar() { // No sidebar required on Single product, cart and checkout pages. if ( is_product() || is_cart() || is_checkout() ) { return; } // Replace default sidebar with Filters sidebar on Product archive pages. if ( is_shop() || is_product_taxonomy() ) { bayleaf_widgets( 'wc-archive-filters', 'wc-archive-filters sidebar-widget-area', esc_html__( 'WooCommerce - Procuct Archive Filters', 'bayleaf' ), 'wc-archive-filters' ); } } /** * Add shopping cart to site header widgets area. * * If default widget area is active, this function will add shopping cart to it. * * @since 1.0.0 * * @param arrray $callbacks Array of callback functions (may be with args). * @return string */ public function header_widgets( $callbacks ) { if ( bayleaf_get_mod( 'bayleaf_woo_mini_cart', 'none' ) ) { array_unshift( $callbacks, [ [ $this, 'add_cart_icon' ] ] ); } return $callbacks; } /** * Header Cart markup. * * @since 1.0.0 */ public function add_cart_icon() { $cart_contents_count = WC()->cart->get_cart_contents_count(); $cart_class = $cart_contents_count ? '' : ' screen-reader-text'; // Shopping Text. $cart_text = $cart_contents_count ? esc_html__( 'Continue Shopping', 'bayleaf' ) : esc_html__( 'Start Shopping', 'bayleaf' ); // Markup for number of items added to the cart (if any). $display_items_count = sprintf( '%2$s', $cart_class, absint( $cart_contents_count ) ); // Shop page link markup. $shopping_page_link = sprintf( '%2$s %3$s', esc_url( wc_get_page_permalink( 'shop' ) ), $cart_text, bayleaf_get_icon( [ 'icon' => 'long-arrow-right' ] ) ); // Shop cart widget toggle button. printf( '', is_cart() || is_checkout() ? 'disabled' : '', bayleaf_get_icon( [ 'icon' => 'cart' ] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped esc_html__( 'View shopping cart', 'bayleaf' ), $display_items_count // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); // Display woocommerce cart widget. the_widget( 'WC_Widget_Cart', [ 'title' => '' ], [ 'before_widget' => '
', 'after_widget' => $shopping_page_link . '
', ] ); } /** * Cart Fragments to be updated. * Ensure cart contents update when products are added to the cart via AJAX * * @param array $fragments Fragments to refresh via AJAX. * @return array Fragments to refresh via AJAX */ public function update_cart_on_ajax( $fragments ) { $cart_contents_count = WC()->cart->get_cart_contents_count(); $cart_class = $cart_contents_count ? '' : ' screen-reader-text'; // Text to display for 'Shop' page link. $cart_text = $cart_contents_count ? esc_html__( 'Continue Shopping', 'bayleaf' ) : esc_html__( 'Start Shopping', 'bayleaf' ); // Update number of items in the cart. $fragments['span.wc-cart-items'] = '' . absint( $cart_contents_count ) . ''; // Update shop page link text. $fragments['a.wc-shop-pagelink'] = '' . $cart_text . ' ' . bayleaf_get_icon( [ 'icon' => 'long-arrow-right' ] ) . ''; return $fragments; } /** * Modify mini cart remove link button. Add delete icon inplace of 'x'. * * @since 1.0.0 * * @param string $markup Cart remove link markup. * @return string */ public function mini_cart_remove_link( $markup ) { return str_replace( '×', bayleaf_get_icon( [ 'icon' => 'trash' ] ), $markup ); } /** * Extend the default WooCommerce product classes. * * @since 1.0.0 * * @param array $classes Classes for the WooCommerce Product. * @return array */ public function woocommerce_product_classes( $classes ) { if ( ! is_woocommerce() ) { return $classes; } global $product; $attachment_ids = $product->get_gallery_image_ids(); if ( $attachment_ids && is_array( $attachment_ids ) && count( $attachment_ids ) ) { $classes[] = 'multiple-product-images'; } return $classes; } /** * Extend the default WooCommerce body classes. * * @since 1.0.0 * * @param array $classes Classes for the WooCommerce Pages. * @return array */ public function woocommerce_body_classes( $classes ) { if ( is_shop() || is_product_category() || is_product_tag() ) { // Remove default sidebar layout classes. $vals = [ 'no-sidebar', 'sidebar-left', 'sidebar-right' ]; foreach ( $vals as $val ) { $key = array_search( $val, $classes, true ); if ( false !== $key ) { unset( $classes[ $key ] ); } } // Add Shop page specific classes. if ( ! is_active_sidebar( 'wc-archive-filters' ) ) { $classes[] = 'no-sidebar'; } else { $classes[] = bayleaf_get_mod( 'bayleaf_woo_shop_layout', 'attr' ); } } return $classes; } /** * Replace wooCommerce default product searchform. * * @since 1.0.0 * * @param str $form Product Searchform markup. * @return string */ public function product_search_form( $form ) { ob_start(); bayleaf_get_template_partial( 'add-on/woocommerce', 'searchform' ); $form = ob_get_clean(); return $form; } /** * Add out of stock text on archive pages. * * @since 1.0.0 */ public function out_of_stock() { $classes = get_post_class(); // Check if 'outofstock' class exist for current product. if ( in_array( 'outofstock', $classes, true ) ) { printf( '%s', esc_html__( 'Out of stock', 'bayleaf' ) ); } } /** * Add wrapper markup on woocommerce product in loop. * * @since 1.0.0 */ public function product_wrapper_open() { echo '
'; } /** * Add wrapper close markup on woocommerce product in loop. * * @since 1.0.0 */ public function product_wrapper_close() { echo '
'; } /** * Display rating HTML even if no rating has been given to the product. * * @since 1.0.0 * * @param str $html Rating html markup. * @param float $rating Rating being shown. * @param int $count Total number of ratings. * @return string */ public function modify_rating_html( $html, $rating, $count ) { if ( 0 < $rating ) { return $html; } else { $html = '
'; $html .= wc_get_star_rating_html( $rating, $count ); $html .= '
'; } return $html; } /** * Remove flex wrapper class to appropriate site elements. * * @since 1.0.0 * * @param array $attr attribute values array. * @return array */ public function remove_wrapper( $attr ) { if ( is_shop() || is_product_category() || is_product_tag() ) { // Remove default wrapper classes. $attr['class'] = str_replace( [ 'flex-wrapper' ], 'wrapper', $attr['class'] ); } return $attr; } /** * Set theme customizer sections. * * @since 1.0.0 * * @param array $sections array of theme customizer sections. * @return array Returns array of theme customizer sections. */ public function customizer_section( $sections = [] ) { return array_merge( $sections, [ 'bayleaf_woocommerce_section' => [ 'title' => esc_html__( 'Theme Options', 'bayleaf' ), 'panel' => 'woocommerce', ], ] ); } /** * Set theme customizer controls and settings. * * @since 1.0.0 * * @param array $controls array of theme controls and settings. * @return array Returns array of theme controls and settings. */ public function customizer_controls( $controls = [] ) { return array_merge( $controls, [ [ 'label' => esc_html__( 'Shop Page Sidebar Layout', 'bayleaf' ), 'section' => 'bayleaf_woocommerce_section', 'setting' => 'bayleaf_woo_shop_layout', 'type' => 'select', 'choices' => [ 'sidebar-left' => esc_html__( 'Sidebar-Content', 'bayleaf' ), 'sidebar-right' => esc_html__( 'Content-Sidebar', 'bayleaf' ), ], ], [ 'label' => esc_html__( 'Show WooCommerce mini cart in Site Header.', 'bayleaf' ), 'section' => 'bayleaf_woocommerce_section', 'setting' => 'bayleaf_woo_mini_cart', 'type' => 'checkbox', ], ] ); } /** * Set default values for theme customization options. * * @since 1.0.0 * * @param array $defaults Array of customizer option default values. * @return array Returns Array of customizer option default values. */ public function customizer_defaults( $defaults = [] ) { return array_merge( $defaults, [ 'bayleaf_woo_shop_layout' => 'sidebar-left', 'bayleaf_woo_mini_cart' => 1, ] ); } /** * Add items to widget title area. * * @param array $after_title Items before closing of widget title. * @param array $instance Settings for the current widget instance. * @return str */ public function woo_wid_title( $after_title, $instance ) { $link_html = ''; // Change only if theme specific after_title args has not been altered. if ( '' !== $after_title ) { return $after_title; } $link_html = sprintf( '%2$s %3$s', esc_url( wc_get_page_permalink( 'shop' ) ), esc_html__( 'View Shop', 'bayleaf' ), bayleaf_get_icon( array( 'icon' => 'long-arrow-right' ) ) ); return '' . $link_html . ''; } /** * Enqueue scripts and styles to front end. * * @since 1.0.0 */ public function enqueue_front() { wp_enqueue_script( 'bayleaf_woocommerce_script', get_template_directory_uri() . '/add-on/woocommerce/assets/woocommerce.js', [], BAYLEAF_THEME_VERSION, true ); wp_enqueue_style( 'bayleaf_woocommerce_style', get_template_directory_uri() . '/add-on/woocommerce/assets/woocommerce.css', [], BAYLEAF_THEME_VERSION, 'all' ); wp_style_add_data( 'bayleaf_woocommerce_style', 'rtl', 'replace' ); } /** * Bug fix for WooCommerce 'wc_change_get_terms_defaults' function in 'includes/wc-term-fruntions.php'. * * To be removed once this bug is resolved in WooCommerce. * * @since 1.3.6 * * @param array $defaults An array of default get_terms() arguments. * @param array $taxonomies An array of taxonomies. * @return array */ public function bug_fix_wc_change_get_terms_defaults( $defaults, $taxonomies ) { if ( is_array( $taxonomies ) && ! isset( $taxonomies[0] ) ) { remove_filter( 'get_terms_defaults', 'wc_change_get_terms_defaults', 10, 2 ); return $defaults; } return $defaults; } /** * Register the custom Widget. * * @since 1.0.0 */ public function register_custom_widget() { require_once get_template_directory() . '/add-on/woocommerce/class-woocommerce-products.php'; register_widget( 'bayleaf\Woocommerce_Products' ); } } WooCommerce::init();