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('shopical-woocommerce-style', $inline_font);
}
//add_action('wp_enqueue_scripts', 'shopical_woocommerce_scripts', 9999);
/**
* 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 shopical_woocommerce_active_body_class($classes)
{
$classes[] = 'woocommerce-active';
return $classes;
}
add_filter('body_class', 'shopical_woocommerce_active_body_class');
//Shop page control
if (!function_exists('shopical_loop_shop_columns')) {
function shopical_loop_shop_columns($cols)
{
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = shopical_get_option('store_product_shop_page_row');;
return $cols;
}
}
add_filter('loop_shop_columns', 'shopical_loop_shop_columns', 20);
/**
* Products per page.
*
* @return integer number of products.
*/
function shopical_woocommerce_products_per_page()
{
$product_loop = shopical_get_option('store_product_shop_page_product_per_page');;
return $product_loop;
}
add_filter('loop_shop_per_page', 'shopical_woocommerce_products_per_page');
add_filter('woocommerce_product_thumbnails_columns', 'shopical_woocommerce_thumbnail_columns');
/**
* Default loop columns on product archives.
*
* @return integer products per row.
*/
function shopical_woocommerce_loop_columns()
{
$cols = shopical_get_option('store_product_shop_page_row');
return $cols;
}
add_filter('loop_shop_columns', 'shopical_woocommerce_loop_columns');
/**
* Remove product zoom
*/
if (!function_exists('shopical_remove_product_zoom')) {
/**
* Product columns wrapper.
*
* @return void
*/
function shopical_remove_product_zoom($tabs)
{
$product_zoom = shopical_get_option('store_product_page_product_zoom');
if ($product_zoom == 'no') {
remove_theme_support('wc-product-gallery-zoom');
remove_theme_support('wc-product-gallery-lightbox');
}
return $tabs;
}
}
add_action('wp_loaded', 'shopical_remove_product_zoom', 9999);
/**
* Product gallery thumnbail columns.
*
* @return integer number of columns.
*/
function shopical_woocommerce_thumbnail_columns()
{
$cols = shopical_get_option('store_product_page_gallery_thumbnail_columns');
return $cols;
}
/**
* Remove related products output
*/
if (!function_exists('shopical_remove_review_tab')) {
/**
* Product columns wrapper.
*
* @return void
*/
function shopical_remove_review_tab($tabs)
{
$review_tab = shopical_get_option('store_product_page_review_tab');
if ($review_tab == 'no') {
unset($tabs['reviews']);
}
return $tabs;
}
}
add_filter('woocommerce_product_tabs', 'shopical_remove_review_tab', 98, 1);
/**
* Related Products Args.
*
* @param array $args related products args.
* @return array $args related products args.
*/
function shopical_woocommerce_related_products_args($args)
{
$posts_per_page = shopical_get_option('store_product_page_related_products_per_page');
$cols = shopical_get_option('store_product_page_related_products_per_row');
$defaults = array(
'posts_per_page' => $posts_per_page,
'columns' => $cols,
);
$args = wp_parse_args($defaults, $args);
return $args;
}
add_filter('woocommerce_output_related_products_args', 'shopical_woocommerce_related_products_args');
/**
* Remove related products output
*/
if (!function_exists('shopical_remove_related_products')) {
/**
* Product columns wrapper.
*
* @return void
*/
function shopical_remove_related_products()
{
$related_products = shopical_get_option('store_product_page_related_products');
if ($related_products == 'no') {
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
}
}
add_action('wp_loaded', 'shopical_remove_related_products');
if (!function_exists('shopical_woocommerce_product_columns_wrapper')) {
/**
* Product columns wrapper.
*
* @return void
*/
function shopical_woocommerce_product_columns_wrapper()
{
$columns = shopical_woocommerce_loop_columns();
echo '
';
}
}
add_action('woocommerce_before_shop_loop', 'shopical_woocommerce_product_columns_wrapper', 40);
if (!function_exists('shopical_woocommerce_product_columns_wrapper_close')) {
/**
* Product columns wrapper close.
*
* @return void
*/
function shopical_woocommerce_product_columns_wrapper_close()
{
echo '
';
}
}
add_action('woocommerce_after_shop_loop', 'shopical_woocommerce_product_columns_wrapper_close', 40);
/**
* 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);
remove_action('wp_footer', 'woocommerce_demo_store', 10);
if (!function_exists('shopical_woocommerce_wrapper_before')) {
/**
* Before Content.
*
* Wraps all WooCommerce content in wrappers which match the theme markup.
*
* @return void
*/
function shopical_woocommerce_wrapper_before()
{
?>
'product',
'post_status' => 'published',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $category_id
),
array(
'taxonomy' => 'product_visibility',
'terms' => array('exclude-from-catalog'),
'field' => 'name',
'operator' => 'NOT IN',
),
),
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
),
array(
'key' => '_min_variation_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
)
),
// array(
// 'key' => '_stock_status',
// 'value' => 'instock'
// ),
)
);
$query = new WP_Query($args);
$count = $query->found_posts;
return absint($count);
}
}
if (!function_exists('shopical_product_count')) {
function shopical_product_count($category_id = 0)
{
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
//'no_found_rows' => 1,
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'nopaging' => true,
'fields' => 'ids',
'hide_empty' => true,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'term_taxonomy_id',
'terms' => $category_id, // Replace with the parent category ID
'include_children' => true,
),
),
);
$query = new WP_Query($args);
$count = $query->found_posts;
return absint($count);
}
}
/**
* Sample implementation of the WooCommerce Mini Cart.
*
* You can add the WooCommerce Mini Cart to header.php like so ...
*
*
*/
if (!function_exists('shopical_woocommerce_header_cart')) {
/**
* Display Header Cart.
*
* @return void
*/
function shopical_woocommerce_header_cart()
{
$aft_enable_minicart = shopical_get_option('aft_enable_minicart');
if($aft_enable_minicart == false){
return;
}
if (is_cart()) {
$class = 'current-menu-item';
} else {
$class = '';
}
?>
cart->get_cart_contents_count(), 'shopical'),
WC()->cart->get_cart_contents_count()
);
?>
cart->get_cart_subtotal()); ?>
';
echo do_shortcode("[yith_wcwl_add_to_wishlist]");
echo '';
}
}
//$enable_wishlists_on_listings = shopical_get_option('enable_wishlists_on_listings', true);
//if( $enable_wishlists_on_listings ){
add_action('shopical_woocommerce_add_to_wishlist_button', 'shopical_display_yith_wishlist_loop', 16);
//}
if (!function_exists('shopical_woocommerce_header_wishlist')) {
/**
* Display Header Wishlist.
*
* @return void
*/
function shopical_woocommerce_header_wishlist()
{
?>
yith_wcwl_count_all_products()
));
}
}
}
add_action('wp_ajax_shopical_update_wishlist_count', 'shopical_update_wishlist_count');
add_action('wp_ajax_nopriv_shopical_update_wishlist_count', 'shopical_update_wishlist_count');
if (!function_exists('shopical_display_wishlist_message')) {
/**
* Return Wishlist product added message.
*/
function shopical_display_wishlist_message($msg)
{
if (class_exists('YITH_WCWL')) {
if (property_exists('YITH_WCWL', 'details')) {
$details = YITH_WCWL()->details;
if (is_array($details) && isset($details['add_to_wishlist'])) {
$product_id = $details['add_to_wishlist'];
$product = wc_get_product($product_id);
if (!is_wp_error($product)) {
$product_title = sprintf(__('%s has been added to your wishist.', 'shopical'), '' . $product->get_title() . '');
$product_image = $product->get_image();
ob_start();
?>
';
global $product, $post;
$product_id = $post->ID;
$label = 'Compare';
if (!$product_id) {
$product instanceof WC_Product && $product_id = yit_get_prop($product, 'id', true);
}
$button = '';
if ($product_id) {
// get label
$button .= '
';
}
echo $button;
echo '';
}
}
//$enable_wishlists_on_listings = shopical_get_option('enable_wishlists_on_listings', true);
//if( $enable_wishlists_on_listings ){
add_action('shopical_woocommerce_yith_quick_view_button', 'shopical_display_yith_quickview_loop', 16);
//}
/*Display YITH Compare Buttons at shop page*/
if (!function_exists('shopical_display_yith_compare_loop')) {
/**
* Display YITH Wishlist Buttons at product archive page
*
*/
function shopical_display_yith_compare_loop()
{
if (!class_exists('YITH_Woocompare')) {
return;
}
echo '';
global $product, $post;
$product_id = $post->ID;
if (!$product_id) {
$product instanceof WC_Product && $product_id = yit_get_prop($product, 'id', true);
}
$button = '';
if ($product_id) {
$button = do_shortcode('[yith_compare_button type="link" button_text=""]');
}
echo $button;
echo '
';
}
}
//$enable_wishlists_on_listings = shopical_get_option('enable_wishlists_on_listings', true);
//if( $enable_wishlists_on_listings ){
add_action('shopical_woocommerce_yith_compare_button', 'shopical_display_yith_compare_loop', 16);
//}
if (!function_exists('shopical_sale_flash')) {
function shopical_sale_flash($content, $post, $product)
{
$sale_flash = shopical_get_option('store_single_sale_text');
if (!empty($sale_flash)) {
$content = '' . $sale_flash . '';
}
return $content;
}
}
add_filter('woocommerce_sale_flash', 'shopical_sale_flash', 10, 3);
/*Display YITH Quickview Buttons at shop page*/
if (!function_exists('shopical_add_to_cart_text')) {
function shopical_add_to_cart_text($add_to_cart_texts)
{
global $product;
if(is_object( $product ) && method_exists( $product,'get_type')){
$product_type = $product->get_type();
}else{
$product_type = $product->product_type;
}
$simple = shopical_get_option('store_simple_add_to_cart_text');
if ($product_type == 'simple') {
return $simple;
}
return $add_to_cart_texts;
}
}
// Single Product
add_filter('woocommerce_product_add_to_cart_text', 'shopical_add_to_cart_text', 10, 2);
/*Display YITH Quickview Buttons at shop page*/
if (!function_exists('shopical_single_add_to_cart_text')) {
function shopical_single_add_to_cart_text()
{
$button_texts = shopical_get_option('store_single_add_to_cart_text');
return $button_texts; // Change this to change the text on the Single Product Add to cart button.
}
}
// Single Product
add_filter('woocommerce_product_single_add_to_cart_text', 'shopical_single_add_to_cart_text');
if (!function_exists('shopical_woocommerce_template_loop_hooks')) :
function shopical_woocommerce_template_loop_hooks()
{
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash');
remove_action('woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title');
add_action('shopical_woocommerce_template_loop_product_link_open', 'woocommerce_template_loop_product_link_open');
add_action('shopical_woocommerce_template_loop_product_link_close', 'woocommerce_template_loop_product_link_close');
add_action('shopical_woocommerce_show_product_loop_sale_flash', 'woocommerce_show_product_loop_sale_flash');
add_action('shopical_woocommerce_template_loop_product_thumbnail', 'woocommerce_template_loop_product_thumbnail');
add_action('shopical_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title');
add_action('shopical_woocommerce_template_loop_rating', 'woocommerce_template_loop_rating', 5);
add_action('shopical_woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price');
add_action('shopical_woocommerce_template_loop_add_to_cart', 'woocommerce_template_loop_add_to_cart');
}
endif;
add_action('wp_loaded', 'shopical_woocommerce_template_loop_hooks');
/**
* Live autocomplete search feature.
*
* @since 1.0.0
*/
function shopical_ajax_search()
{
$results = new WP_Query(array(
'post_type' => array('product'),
'post_status' => 'publish',
'nopaging' => true,
'posts_per_page' => 100,
's' => stripslashes($_POST['search']),
'meta_query' => array(
array(
'key' => '_visibility',
'value' => 'hidden',
'compare' => '!=',
)
),
));
$items = array();
if (!empty($results->posts)) {
foreach ($results->posts as $result) {
$items[] = $result->post_title;
}
}
wp_send_json_success($items);
}
add_action('wp_ajax_search_site', 'shopical_ajax_search');
add_action('wp_ajax_nopriv_search_site', 'shopical_ajax_search');
add_filter('body_class', 'shopical_body_class');
function shopical_body_class($classes)
{
// foreach ( $classes as $key => $value ) {
// if ( $value == 'woocommerce-page' ) unset( $classes[ $key ] );
// }
if (!is_woocommerce()) {
$classes[] = 'woocommerce';
}
return $classes;
}
function shopical_woocommerce_shop_loop_subcategory_title($category)
{
$product_count = 'true';
$onsale_product_count = 'true';
$products_count = shopical_product_count($category->term_id);
$products_count = ($product_count == 'true') ? $products_count : 0;
$product_onsale = shopical_onsale_product_count($category->term_id);
$product_onsale = ($onsale_product_count == 'true') ? $product_onsale : 0;
?>
name); ?>
0): ?>
%s
item', '%sitems', $products_count, 'shopical'), number_format_i18n($products_count)); ?>
0):
$sale_flash_text = shopical_get_option('store_single_sale_text');
?>
0):
?>
display_name;
} else {
$account_texts = __('Login', 'shopical');
if (get_option('users_can_register')) {
$account_texts = __('Login/Register', 'shopical');
}
}
$myaccount_page_id = get_option('woocommerce_myaccount_page_id');
if ($myaccount_page_id) {
$myaccount_page_url = get_permalink($myaccount_page_id);
}
?>