270,
'single_image_width' => 540,
'product_grid' => array(
'default_rows' => 3,
'min_rows' => 1,
'default_columns' => 3,
'min_columns' => 2,
'max_columns' => 5,
),
)
)
);
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
add_action( 'after_setup_theme', 'astha_woocommerce_setup' );
/**
* WooCommerce specific scripts & stylesheets.
* WooCommerce Responsive File added here
*
* @since 1.0.0.29 - Added Responsive WooComerce file
*
* @since 1.0.0
*
* @return void
*/
function astha_woocommerce_scripts() {
wp_enqueue_style( 'astha-woocommerce-style', get_template_directory_uri() . '/assets/css/woocommerce.css', array(), ASTHA_VERSION );
$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( 'astha-woocommerce-style', $inline_font );
/**
* Responsive File for WooCommerce Plugin Only
* We will Add Responsive CSS Style here, Because WooCommerce Responsive file will
* load, When Woocommerce Installed and activated only.
*
* *****************************
* WooCommerce's Third Party Plugin's responsive Style also load from here
*/
wp_enqueue_style( 'astha-responsive-woocommerce', get_template_directory_uri() . '/assets/css/responsive-woocommerce.css', array(), ASTHA_VERSION );
/**
* WooCommerce Related JS will load, When only Woocommerce Install
*
* @since 1.0.0.29
*/
wp_enqueue_script( 'astha-woocommerce-custom-js', get_template_directory_uri() . '/assets/js/woocommerce.js', array(), ASTHA_VERSION, true );
}
add_action( 'wp_enqueue_scripts', 'astha_woocommerce_scripts', 20 );
/**
* Disable the default WooCommerce stylesheet.
*
* Removing the default WooCommerce stylesheet and enqueing your own will
* protect you during WooCommerce core updates.
*
* @link https://docs.woocommerce.com/document/disable-the-default-stylesheet/
*/
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
/**
* Add 'woocommerce-active' class to the body tag.
*
* @param array $classes CSS classes applied to the body tag.
* @return array $classes modified to include 'woocommerce-active' class.
*/
function astha_woocommerce_active_body_class( $classes ) {
$classes[] = 'woocommerce-active';
return $classes;
}
add_filter( 'body_class', 'astha_woocommerce_active_body_class' );
/**
* Related Products Args.
*
* @param array $args related products args.
* @return array $args related products args.
*/
function astha_woocommerce_related_products_args( $args ) {
$defaults = array(
'posts_per_page' => 3,
'columns' => 3,
'orderby' => 'rand', // @codingStandardsIgnoreLine.
);
/**
* User able to change Related product arg by
* using WooCommerce Default Filter Hook
* @Hook woocommerce_output_related_products_args
*
* Also able to do it by our Theme's Hook
*/
$defaults = apply_filters( 'astha_wc_related_products_args', $defaults );
$args = wp_parse_args( $defaults, $args );
return $args;
}
add_filter( 'woocommerce_output_related_products_args', 'astha_woocommerce_related_products_args' );
/**
* Remove default WooCommerce wrapper.
*/
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( 'astha_woocommerce_wrapper_before' ) ) {
/**
* Before Content.
*
* Wraps all WooCommerce content in wrappers which match the theme markup.
*
* @return void
*/
function astha_woocommerce_wrapper_before() {
?>
*/
if ( ! function_exists( 'astha_woocommerce_cart_link_fragment' ) ) {
/**
* Cart Fragments.
*
* 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.
*/
function astha_woocommerce_cart_link_fragment( $fragments ) {
ob_start();
astha_woocommerce_cart_link();
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
}
add_filter( 'woocommerce_add_to_cart_fragments', 'astha_woocommerce_cart_link_fragment' );
if ( ! function_exists( 'astha_woocommerce_cart_link' ) ) {
/**
* Cart Link.
*
* Displayed a link to the cart including the number of items present and the cart total.
*
* @return void
*/
function astha_woocommerce_cart_link() {
?>
cart->get_cart_contents_count(), 'astha' );
$item_count_text = apply_filters( 'astha_minicart_item_text', $item_count_text, WC()->cart );
if( WC()->cart->get_cart_contents_count() > 0 ){
?>
cart->get_cart_contents_count() ); ?>
cart->get_cart_subtotal() ); ?>
' );
do_action( 'astha_wc_loop_wrapper_top' );
}
}
//Already template override completed. so no need this action. Removed at 1.0.0.61 when we have completed first complete deadline
//add_action( 'woocommerce_after_shop_loop_item', 'astha_shop_loop_cart_before', 5 );
if ( ! function_exists( 'astha_shop_loop_cart_after' ) ) {
/**
* Add Tag at the end of @Hook woocommerce_after_shop_loop_item
* I have added a div tag
* Because we need to change HTML markup
*
* @return void
*/
function astha_shop_loop_cart_after() {
$loop_wrp = apply_filters( 'astha_wc_loop_wrapper', true );
if( ! $loop_wrp ){
return;
}
do_action( 'astha_wc_loop_wrapper_bottom' );
echo wp_kses_post( '
' );
}
}
//Already template override completed. so no need this action. Removed at 1.0.0.61 when we have completed first complete deadline
//add_action( 'woocommerce_after_shop_loop_item', 'astha_shop_loop_cart_after', PHP_INT_MAX );
if ( ! function_exists( 'astha_shop_loop_thumbs_before' ) ) {
/**
* Add Tag at the begining of @Hook woocommerce_after_shop_loop_item
* I have added a div tag
* Because we need to change HTML markup
*
* @return void
*/
function astha_shop_loop_thumbs_before() {
echo wp_kses_post( '' );
}
}
//To add tag with class at the first of this loop
add_action( 'woocommerce_before_shop_loop_item_title', 'astha_shop_loop_thumbs_before', 9 );
if ( ! function_exists( 'astha_shop_loop_thumbs_after' ) ) {
/**
* Add Tag at the end of @Hook woocommerce_after_shop_loop_item
* I have added a div tag
* Because we need to change HTML markup
*
* @return void
*/
function astha_shop_loop_thumbs_after() {
echo wp_kses_post( '' );
}
}
//To add tag with class at the last of this loop
add_action( 'woocommerce_before_shop_loop_item_title', 'astha_shop_loop_thumbs_after', 11 );
/**
* Single Product ACTION HOOK ARRAGE
* And Management
* for
* Product Meda
* Bread Crumb
* title
* ETC
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
$astha_breadcrumb = astha_option( 'astha_breadcrumb_switch', false );
if( $astha_breadcrumb ){
add_action( 'woocommerce_single_product_summary', 'woocommerce_breadcrumb', 0 );
}
if( !function_exists( 'astha_get_shop_layout' ) ) {
function astha_get_shop_layout(){
$layout_key_name = 'shop';
//Check from Cookie
if( isset( $_COOKIE[$layout_key_name] ) && ! empty( $_COOKIE[$layout_key_name] ) ) {
return $_COOKIE[$layout_key_name];
}
//First Check from link
if( ! isset( $_COOKIE[$layout_key_name] ) && isset( $_GET['layout'] ) && ! empty( $_GET['layout'] ) ){
$layout = $_GET['layout'];
//setcookie( $layout_key_name, $layout, time() + 86400 * 3 );
return $layout;
}
$shop_layout = astha_option('layout_shop_wc', 'shop-grid');
return $shop_layout;
}
}
if( !function_exists( 'astha_catalog_display_options' ) ) {
/**
* Adding Product View Option for WooCommerce Shop Page
* for
* Grid View Button
* And List View Button
*
* @return void It will display two view option.
*/
function astha_catalog_display_options() {
//$_wc_astha = '_wc';
$layout = astha_get_shop_layout();//astha_option( 'layout_shop' . $_wc_astha, 'shop-grid' );
$pageURL = 'http';
if (isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
?>
*
* @link https://woocommerce.github.io/code-reference/files/woocommerce-templates-content-product.html#source-view.57 Template file code from WooCommerce
*/
function astha_wc_shop_loop_short_description( ) {
global $product;
$short_description = $product->get_short_description();
$short_description = apply_filters( 'astha_product_loop_desc', $short_description, $product );
?>
true,
'taxonomy' => 'product_cat',
'class' => 'post-navigation',
'prev_text' => '' . esc_html__( 'Previous:', 'astha' ) . ' %title
',
'next_text' => '' . esc_html__( 'Next:', 'astha' ) . ' %title
',
)
);
}
}
if( class_exists( 'YITH_WCWL_Shortcode' ) ){
add_action( 'woocommerce_after_add_to_cart_button', 'astha_wishlist_control_by_shortcode' );
function astha_wishlist_control_by_shortcode(){
$atts = array();
echo YITH_WCWL_Shortcode::add_to_wishlist( $atts );
}
}
/**
* Just need to enable for showing enxt prev button on single product page
*/
//add_action( 'woocommerce_before_main_content', 'astha_wc_sinle_product_next_prev_link', 19 );
//add_action( 'woocommerce_single_product_summary', 'astha_wc_sinle_product_next_prev_link', PHP_INT_MAX );