File: /home/dermova/www/india/wp-content/themes/ri-colias/included/theme-function/rit-woocomerce.php
<?php
/**
* Text Domain: woocommerce
* Domain Path: /i18n/languages/
*
* @package WooCommerce
* @category Core
* @author WooThemes
*/
/* WooCommerce - Get WooCommerce version number ===================================================================== */
function rit_get_woo_version_number() {
// If get_plugins() isn't available, require it
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Create the plugins folder and file variables
$plugin_folder = get_plugins( '/' . 'woocommerce' );
$plugin_file = 'woocommerce.php';
// If the plugin version number is set, return it
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
return $plugin_folder[$plugin_file]['Version'];
} else {
// Otherwise return null
return NULL;
}
}
/* WooCommerce - Disable the default stylesheet WooCommerce ========================================================= */
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
/* WooCommerce - Remove actions ===================================================================================== */
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
/* WooCommerce - Ajax add to cart =================================================================================== */
add_filter( 'add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
ct_cartbox();
$fragments['#cart'] = ob_get_clean();
return $fragments;
}
if(!function_exists('ct_cartbox')){
function ct_cartbox(){
global $woocommerce;
?>
<div id="cart">
<div class="mini-cart btn-header clearfix" role="contentinfo">
<span class="icon-cart text-items">
<?php echo sprintf(_n(' <span class="mini-cart-items">%d</span> ', '<span class="mini-cart-items">%d</span>', $woocommerce->cart->cart_contents_count, 'ri-colias'), $woocommerce->cart->cart_contents_count); ?>
</span>
<div class="group-mini-cart">
<div class="text-cart"><?php esc_html_e('My Cart','ri-colias'); ?></div>
<div class="text-items">
<?php echo sprintf(_n(' <span class="mini-cart-items"></span> ', '', $woocommerce->cart->cart_contents_count, 'ri-colias'), $woocommerce->cart->cart_contents_count);?> <?php echo $woocommerce->cart->get_cart_total(); ?>
</div>
</div>
</div>
<div class="cart-box">
<?php woocommerce_mini_cart(); ?>
</div>
</div>
<?php }
}
/* WooCommerce - Ajax remover cart ================================================================================== */
add_action( 'wp_ajax_cart_remove_product', 'rit_woo_remove_product' );
add_action( 'wp_ajax_nopriv_cart_remove_product', 'rit_woo_remove_product' );
function rit_woo_remove_product() {
$cart = WC()->instance()->cart;
$id = $_POST['product_id'];
$cart_id = $cart->generate_cart_id($id);
$cart_item_id = $cart->find_product_in_cart($cart_id);
if($cart_item_id){
$cart->set_quantity($cart_item_id,0);
}
$output = array();
$output['subtotal'] = $cart->get_cart_subtotal();
$output['count'] = $cart->cart_contents_count;
print_r( json_encode( $output ) );
exit();
}
/* WooCommerce - Hide WooCommerce page ============================================================================== */
add_filter('woocommerce_show_page_title', 'rit_woocommerce_show_page_title');
function rit_woocommerce_show_page_title($args) {
return false;
}
/* WooCommerce - Show grid/list toggle buttons ====================================================================== */
add_action('woocommerce_before_shop_loop', 'rit_grid_list_toggle', 40);
function rit_grid_list_toggle() {
?>
<ul class="switch-layout pull-left list-unstyled list-inline">
<li>
<span><?php esc_html_e('View as :','ri-colias')?></span>
</li>
<li>
<a title="Grid View" class="products-grid">
<i class="fa fa-th-large"></i>
</a>
</li>
<li>
<a title="List View" class="products-list">
<i class="fa fa-th-list"></i>
</a>
</li>
</ul>
<?php
}
/* WooCommerce - Image description category========================================================================== */
add_action('woocommerce_archive_description', 'rit_woocommerce_category_image', 2);
function rit_woocommerce_category_image() {
if ( is_product_category() ){
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if ($term) {
$thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<div class="wrapper-thumb-cat">';
echo '<img src="' . $image . '" class="category-image" alt="' . esc_attr($term->name) . '" />';
echo '</div>';
}
}
}
}
/* WooCommerce - Products per page ================================================================================== */
add_action('woocommerce_before_shop_loop', 'jc_woocommerce_products_per_page', 39);
function jc_get_products_per_page(){
global $woocommerce;
$default = 6;
$count = $default;
$options = jc_get_products_per_page_options();
// capture form data and store in session
if(isset($_POST['jc-woocommerce-products-per-page'])){
// set products per page from dropdown
$products_max = intval($_POST['jc-woocommerce-products-per-page']);
if($products_max != 0 && $products_max >= -1){
if(is_user_logged_in()){
$user_id = get_current_user_id();
$limit = get_user_meta( $user_id, '_product_per_page', true );
if(!$limit){
add_user_meta( $user_id, '_product_per_page', $products_max);
}else{
update_user_meta( $user_id, '_product_per_page', $products_max, $limit);
}
}
$woocommerce->session->jc_product_per_page = $products_max;
return $products_max;
}
}
// load product limit from user meta
if(is_user_logged_in() && !isset($woocommerce->session->jc_product_per_page)){
$user_id = get_current_user_id();
$limit = get_user_meta( $user_id, '_product_per_page', true );
if(array_key_exists($limit, $options)){
$woocommerce->session->jc_product_per_page = $limit;
return $limit;
}
}
// load product limit from session
if(isset($woocommerce->session->jc_product_per_page)){
// set products per page from woo session
$products_max = intval($woocommerce->session->jc_product_per_page);
if($products_max != 0 && $products_max >= -1){
return $products_max;
}
}
return $count;
}
add_filter('loop_shop_per_page','jc_get_products_per_page');
function jc_get_products_per_page_options(){
$options = apply_filters( 'jc_products_per_page', array(
6 => esc_html__('6','ri-colias'),
9 => esc_html__('9','ri-colias'),
15 => esc_html__('15','ri-colias'),
21 => esc_html__('21','ri-colias'),
));
return $options;
}
function jc_woocommerce_products_per_page(){
$options = jc_get_products_per_page_options();
$current_value = jc_get_products_per_page();
?>
<div class="products-per-page pull-right">
<form action="" method="POST" class="woocommerce-products-per-page">
<span><?php esc_html_e('Show','ri-colias' ); ?></span>
<select name="jc-woocommerce-products-per-page" onchange="this.form.submit()">
<?php foreach($options as $value => $name): ?>
<option value="<?php echo esc_attr($value); ?>" <?php selected($value, $current_value); ?>><?php echo esc_attr($name); ?></option>
<?php endforeach; ?>
</select>
</form>
</div>
<?php
}
/* WooCommerce - Hover Image Product ================================================================================ */
remove_action('woocommerce_before_shop_loop_item_title','woocommerce_show_product_loop_sale_flash',10);
add_action('woocommerce_before_shop_loop_item_title', 'rit_loop_product_thumbnail', 10);
function rit_loop_product_thumbnail() {
global $rit_settings;
$size = get_option('shop_catalog_image_size');
$id = get_the_ID();
$size = 'shop_catalog';
$image_product_hover = get_theme_mod('rit_woo_product_hover');
$gallery = get_post_meta($id, '_product_image_gallery', true);
$attachment_image = '';
if (!empty($gallery) && ($image_product_hover != 'off')) {
$gallery = explode(',', $gallery);
$first_image_id = $gallery[0];
$attachment_image = wp_get_attachment_image($first_image_id , $size, false, array('class' => 'hover-image'));
}
$thumb_image = get_the_post_thumbnail($id , $size, array('class' => ''));
if (!$thumb_image) {
if ( wc_placeholder_img_src() ) {
$thumb_image = wc_placeholder_img( $size );
}
}
echo '<span class="inner'.(($attachment_image)?' img-effect':'').'">';
// show images
echo $thumb_image;
echo $attachment_image;
echo '</span>';
}
// change product thumbnail in products widget
function rit_widget_product_thumbnail() {
$id = get_the_ID();
$size = 'shop_thumbnail';
$image_product_hover = get_theme_mod('rit_woo_product_hover');
$gallery = get_post_meta($id, '_product_image_gallery', true);
$attachment_image = '';
if (!empty($gallery) && ($image_product_hover != 'off')) {
$gallery = explode(',', $gallery);
$first_image_id = $gallery[0];
$attachment_image = wp_get_attachment_image($first_image_id , $size, false, array('class' => 'hover-image '));
}
$thumb_image = get_the_post_thumbnail($id , $size, array('class' => ''));
if (!$thumb_image) {
if ( wc_placeholder_img_src() ) {
$thumb_image = wc_placeholder_img( $size );
}
}
echo '<div class="inner'.(($attachment_image)?' img-effect':'').'">';
// show images
echo $thumb_image;
echo $attachment_image;
echo '</div>';
}
/* WooCommerce - Quick view Product ================================================================================= */
// add button
remove_action( 'yith_wcqv_product_summary', 'woocommerce_template_single_add_to_cart', 25 );
add_action( 'yith_wcqv_product_summary', 'woocommerce_template_single_add_to_cart', 18 );