| Server IP : 213.186.33.4 / Your IP : 216.73.216.222 Web Server : Apache System : Linux webm005.cluster103.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64 User : karinebmkh ( 644538) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/karinebmkh/www2/wp-content/themes/novablog/woocommerce-scripts/ |
Upload File : |
<?php
/** gets the url to remove an item from dock cart */
function novablog_get_remove_url( $cart_item_key ) {
global $woocommerce;
$cart_page_id = woocommerce_get_page_id('cart');
if ($cart_page_id)
return apply_filters('woocommerce_get_remove_url', $woocommerce->nonce_url( 'cart', add_query_arg('update_cart', $cart_item_key, get_permalink($cart_page_id))));
}
/**
* Remove from cart/update
**/
function novablog_update_cart_action() {
global $woocommerce;
// Update Cart
if (isset($_GET['update_cart']) && $_GET['update_cart'] && $woocommerce->verify_nonce('cart')) :
$cart_totals = $_GET['update_cart'];
if (sizeof($woocommerce->cart->get_cart())>0) :
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) :
$update = $values['quantity'] - 1;
if ($cart_totals == $cart_item_key)
$woocommerce->cart->set_quantity( $cart_item_key, $update);
endforeach;
endif;
echo json_encode(array('deleted' => 'deleted'));
die();
endif;
}
/**
* Add cart total and shopdock cart to the WC Fragments
*/
function novablog_theme_add_to_cart_fragments( $fragments ) {
ob_start();
get_template_part( 'includes/shopdock' );
$shopdock = ob_get_clean();
$fragments['#shopdock'] = $shopdock;
$total = WC()->cart->get_cart_contents_count();
$cl= $total>0?'icon-menu-count':'icon-menu-count cart_empty';
$fragments['#cart-icon-count .icon-menu-count'] = '<span class="'.$cl.'">' . $total. '</span>';
return $fragments;
}
/**
* Delete cart
*/
function novablog_theme_woocommerce_delete_cart() {
global $woocommerce;
if ( isset($_POST['remove_item']) && $_POST['remove_item'] ) {
$woocommerce->cart->set_quantity( $_POST['remove_item'], 0 );
WC_AJAX::get_refreshed_fragments();
die();
}
}
/**
* Add to cart ajax on single product page
*/
function novablog_theme_woocommerce_add_to_cart() {
ob_start();
WC_AJAX::get_refreshed_fragments();
die();
}
/**
* Remove (unnecessary) success message after a product was added to cart through theme's AJAX method.
*/
function novablog_theme_wc_add_to_cart_message( $message ) {
if ( isset( $_REQUEST['action'] ) && 'theme_add_to_cart' == $_REQUEST['action'] ) {
$message = '';
}
return $message;
}
//Woocommerce product per page
function novablog_overide_product_count($cols)
{
global $novablog_options;
if(isset($novablog_options['woocommerce_items_per_page'])) {
return $novablog_options['woocommerce_items_per_page'];
}
}
add_filter( 'loop_shop_per_page', 'novablog_overide_product_count', 20 );
add_filter( 'woocommerce_show_page_title' , 'woo_hide_page_title' );
function woo_hide_page_title() {
return false;
}
add_action( 'after_setup_theme', 'novablog_woocommerce_support' );
function novablog_woocommerce_support() {
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
// Change number or products per row to 3
add_filter('loop_shop_columns', 'novablog_loop_columns');
if (!function_exists('novablog_loop_columns')) {
function novablog_loop_columns() {
return 3; // 3 products per row
}
}
function novablog_get_cart_items() {
global $woocommerce;
$articles = sizeof( $woocommerce->cart->get_cart() );
$cart = $total_articles = '';
if ( $articles > 0 ) {
$total_articles = $woocommerce->cart->cart_contents_count;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key );
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
$product_price = apply_filters( 'woocommerce_cart_item_price', $woocommerce->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
$string = apply_filters( 'woocommerce_get_remove_url', $woocommerce->cart->get_remove_url( $cart_item_key ));
$cart .= '<li class="cart-item-list clearfix">';
if ( ! $_product->is_visible() ) {
$cart .= str_replace( array( 'http:', 'https:' ), '', $thumbnail );
} else {
$cart .= '<a class="product-image" href="'.esc_url(get_permalink( $product_id )).'">
'.str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . '
</a>';
}
$cart .= '<a title="'.esc_html__( 'Remove this item', 'novablog' ).'" class="remove" href="'.$string.'"><i class="fa fa-times" aria-hidden="true"></i>
</a>';
$cart .= '<div class="product-details"><span class="product-name">' . $product_name .'</span>';
$cart .= '<span class="product-quantity">'. apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity-container">' . sprintf( '%s × %s',$cart_item['quantity'] , '</span>' . $product_price ) , $cart_item, $cart_item_key ) . '</span>';
$cart .= '</div>';
$cart .= '</li>';
}
}
$cart .= '<li class="subtotal"><span class="subtotalwr">' . esc_html__('Estimated total:', 'novablog') . '</span><span> ' . $woocommerce->cart->get_cart_total() . '</span></li>';
$cart .= '<li class="buttons clearfix">
<a href="'.esc_url($woocommerce->cart->get_cart_url()).'" class="btn btn-default btn-normal"><i class="fa fa-bag"></i>'.esc_html__( 'View Cart', 'novablog' ).'</a>
</li>';
} else {
$cart .= '<li><span>' . esc_html__('No products in the cart.','novablog') . '</span></li>';
}
return array('cart' => $cart, 'articles' => $total_articles);
}
function novablog_woomenucart_ajax() {
$cart = novablog_get_cart_items();
echo json_encode($cart);
die();
}
/**
* Fragments
* Adding cart total and shopdock markup to the fragments
*/
add_filter( 'woocommerce_add_to_cart_fragments', 'novablog_theme_add_to_cart_fragments' );
/**
* Theme delete cart hook
* Note: for Add to cart using default WC function
*/
add_action( 'wp_ajax_theme_delete_cart', 'novablog_theme_woocommerce_delete_cart' );
add_action( 'wp_ajax_nopriv_theme_delete_cart', 'novablog_theme_woocommerce_delete_cart' );
/**
* Theme adding cart hook
* Adding cart ajax on single product page
*/
add_action( 'wp_ajax_theme_add_to_cart', 'novablog_theme_woocommerce_add_to_cart' );
add_action( 'wp_ajax_nopriv_theme_add_to_cart', 'novablog_theme_woocommerce_add_to_cart' );
add_action( 'init', 'novablog_update_cart_action');
function novablog_add_cart_in_menu($woo_icon) {
global $woocommerce;
$total_articles = $woocommerce->cart->cart_contents_count;
$get_cart_items = novablog_get_cart_items();
$vertical = false;
$cart_container = '<ul class="sub-menu novablog-submenu-cart">'.((isset($get_cart_items['cart']) && $get_cart_items['cart'] !=='') ? $get_cart_items['cart'] : '<li><span>' . esc_html__('No products in the cart.','novablog') . '</span></li>').'</ul>';
$items = '<li class="novablog-cart menu-item menu-item-has-children has-sub-menu">
<a href="'.esc_url($woocommerce->cart->get_cart_url()).'" class="cart-link" data-type="title" title="cart">
<span class="cart-icon-container">';
$items .= '<i class="'.$woo_icon.'"></i>';
$items .= (( $total_articles !== 0 ) ? '<span class="badge">'.$total_articles.'</span>' : '<span class="badge empty"></span>').'
</span>
</a>
'.$cart_container.
'</li>';
return $items;
}
add_filter( 'woocommerce_output_related_products_args', 'novablog_related_products_args' );
function novablog_related_products_args( $args ) {
$args['posts_per_page'] = 3; // 4 related products
$args['columns'] = 3; // arranged in 2 columns
return $args;
}
?>