includes(); $this->hooks(); do_action( 'beetan_woocommerce_loaded', $this ); } /** * Includes */ public function includes() { require_once get_template_directory() . '/inc/woocommerce/woocommerce-functions.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound } /** * Hooks */ public function hooks() { add_action( 'after_setup_theme', array( $this, 'setup_theme' ) ); add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_filter( 'body_class', array( $this, 'body_class' ) ); add_action( 'wp', array( $this, 'woocommerce_init' ), 1 ); add_action( 'wp', array( $this, 'shop_product_customize' ), 5 ); add_action( 'widgets_init', array( $this, 'register_widgets' ) ); add_action( 'woocommerce_before_main_content', array( $this, 'woocommerce_wrapper_before' ) ); add_action( 'woocommerce_after_main_content', array( $this, 'woocommerce_wrapper_after' ) ); add_action( 'woocommerce_before_shop_loop', array( $this, 'shop_toolbar_open' ) ); add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 20 ); add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 25 ); add_action( 'woocommerce_before_shop_loop', array( $this, 'shop_layout_buttons' ), 30 ); add_action( 'woocommerce_before_shop_loop', array( $this, 'shop_toolbar_close' ), 40 ); add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_cart_link_fragment' ) ); add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_args' ) ); add_filter( 'beetan_get_sidebar', array( $this, 'replace_sidebar' ) ); } public function shop_toolbar_open() { echo '
'; } public function shop_toolbar_close() { echo '
'; } public function shop_layout_buttons() { if ( ! is_shop() && ! is_product_taxonomy() ) { return; } echo ''; } /** * WooCommerce setup theme */ public function setup_theme() { add_theme_support( 'woocommerce', array( 'thumbnail_image_width' => 150, 'single_image_width' => 300, 'product_grid' => array( 'default_rows' => 3, 'min_rows' => 1, 'default_columns' => 4, 'min_columns' => 1, 'max_columns' => 6, ), ) ); add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); } /** * WooCommerce specific scripts & stylesheets. */ public function enqueue_scripts() { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( 'beetan-woocommerce-style', esc_url( get_theme_file_uri( "/assets/css/woocommerce{$suffix}.css" ) ), array(), beetan_assets_version( "/assets/css/woocommerce{$suffix}.css" ) ); $font_path = WC()->plugin_url() . '/assets/fonts/'; $inline_font = '@font-face { font-family: "star"; src: url("' . $font_path . 'star.eot"); src: url("' . $font_path . 'star.eot?#iefix") format("embedded-opentype"), url("' . $font_path . 'star.woff") format("woff"), url("' . $font_path . 'star.ttf") format("truetype"), url("' . $font_path . 'star.svg#star") format("svg"); font-weight: normal; font-style: normal; }'; wp_add_inline_style( 'beetan-woocommerce-style', $inline_font ); wp_enqueue_script( 'beetan-woocommerce-scripts', esc_url( get_theme_file_uri( "/assets/js/woocommerce{$suffix}.js" ) ), array( 'jquery' ), beetan_assets_version( "/assets/js/woocommerce{$suffix}.js" ), true ); } /** * Add 'woocommerce-active' class to the body tag. * * @param $classes * * @return mixed */ public function body_class( $classes ) { $classes[] = 'woocommerce-active'; return $classes; } /** * Remove WooCommerce Default actions */ public function woocommerce_init() { remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 ); remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); } /** * WooCommerce Default Shop Product Customization */ public function shop_product_customize() { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 10 ); add_action( 'woocommerce_shop_loop_item_title', 'beetan_shop_product_title', 10 ); add_action( 'woocommerce_shop_loop_item_title', 'beetan_product_sale_percentage', 8 ); add_action( 'woocommerce_shop_loop_item_title', 'beetan_product_brand', 9 ); add_action( 'woocommerce_before_shop_loop_item_title', 'beetan_shop_product_img_overlay', 20 ); add_action( 'beetan_shop_thumbnail_overlay_content', 'beetan_shop_item_view_details_button', 15 ); if ( defined( 'YITH_WCQV' ) ) { remove_action( 'woocommerce_after_shop_loop_item', array( YITH_WCQV_Frontend(), 'yith_add_quick_view_button' ), 15 ); add_action( 'beetan_shop_thumbnail_overlay_content', array( YITH_WCQV_Frontend(), 'yith_add_quick_view_button' ), 10 ); } add_filter( 'woocommerce_sale_flash', '__return_false' ); } /** * WooCommerce Before Content Wrapper. * * @return void */ public function woocommerce_wrapper_before() { echo '
'; if ( 'left_sidebar' == beetan_sidebar_layout() ) { get_sidebar(); } echo '
'; } /** * WooCommerce After Content Wrapper. * * @return void */ public function woocommerce_wrapper_after() { echo '
'; if ( 'right_sidebar' == beetan_sidebar_layout() ) { get_sidebar(); } echo '
'; } public function register_widgets() { register_sidebar( array( 'name' => esc_html__( 'Shop Sidebar', 'beetan' ), 'id' => 'sidebar-product-archive', 'description' => sprintf( __( 'Add widgets here to show in single product page sidebar. Make sure you have enabled Sidebar layout by going to Appearance / Customizer / Sidebar Options.', 'beetan' ), esc_url( admin_url( 'customize.php?autofocus%5Bsection%5D=sidebar_settings_section' ) ) ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => esc_html__( 'Single Product Sidebar', 'beetan' ), 'id' => 'sidebar-product', 'description' => sprintf( __( 'Add widgets here to show in shop page sidebar. Make sure you have enabled Sidebar layout by going to Appearance / Customizer / Sidebar Options.', 'beetan' ), esc_url( admin_url( 'customize.php?autofocus%5Bsection%5D=sidebar_settings_section' ) ) ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } /** * Related Products Args. * * @param array $args related products args. * * @return array $args related products args. */ public function related_products_args( $args ) { $shop_grid = get_option( 'woocommerce_catalog_columns', 4 ); $defaults = array( 'posts_per_page' => absint( $shop_grid ), 'columns' => absint( $shop_grid ), ); $args = wp_parse_args( $defaults, $args ); return $args; } /** * Cart Fragments. * * Ensure cart contents update when products are added to the cart via AJAX. * * @param $fragments * * @return mixed */ public function woocommerce_cart_link_fragment( $fragments ) { ob_start(); $this->woocommerce_cart_link(); $fragments['a.cart-contents'] = ob_get_clean(); return $fragments; } /** * Cart Link. * * Displayed a link to the cart including the number of items present and the cart total. * * @return void */ public function woocommerce_cart_link() { $item_count = WC()->cart->get_cart_contents_count(); ?> shopping_cart
  • woocommerce_cart_link(); ?>