Uname:Linux vps0314.00gate.com 5.15.0-1089-azure #98~20.04.1-Ubuntu SMP Fri May 2 20:18:39 UTC 2025 x86_64

Base Dir : /var/www/vhosts/spaceten.it/salumipasini.spaceten.it

User : spaceten.it_vps0314


403WebShell
403Webshell
Server IP : 194.124.73.198  /  Your IP : 216.73.216.200
Web Server : Apache
System : Linux vps0314.00gate.com 5.15.0-1089-azure #98~20.04.1-Ubuntu SMP Fri May 2 20:18:39 UTC 2025 x86_64
User : spaceten.it_vps0314 ( 10000)
PHP Version : 8.0.30
Disable Function : opcache_get_status
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/vhosts/spaceten.it/salumipasini.spaceten.it/wp-content/themes/Divi-child/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/vhosts/spaceten.it/salumipasini.spaceten.it/wp-content/themes/Divi-child/functions.php
<?php
add_action( 'wp_footer', 'getCategoryName', 10 );



function getCategoryName(){

    global $wp_query;



    if( is_product_category() ) {

        $category_name = woocommerce_page_title(false);

    } elseif ($wp_query->post->ID == 33){

        $category_name = 'shop';

    }





    wp_localize_script('custom-js', 'category_name', $category_name );

}

// Exit if accessed directly

if ( !defined( 'ABSPATH' ) ) exit;



// BEGIN ENQUEUE PARENT ACTION

// AUTO GENERATED - Do not modify or remove comment markers above or below:



if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):

    function chld_thm_cfg_locale_css( $uri ){

        if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )

            $uri = get_template_directory_uri() . '/rtl.css';

        return $uri;

    }

endif;

add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );



if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):

    function chld_thm_cfg_parent_css() {

        wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array() );

    }

endif;

add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );



// END ENQUEUE PARENT ACTION


// ADD CUSTOM CSS AND JS

function add_custom_font() {

    $url = trailingslashit( get_stylesheet_directory_uri() ) .'/Fonts/stylesheet.css';

    wp_register_style('pasini-font', $url);

    wp_enqueue_style('pasini-font');

    wp_enqueue_style ( 'custom-font-awesome', trailingslashit( get_stylesheet_directory_uri() ).'Fonts/stylesheet.css', array () );



    // INTEGRAZIONE FILE CUSTOM.JS E INTEGRAZIONE DELLE TRADUZIONI

    wp_register_script( 'custom-js', get_stylesheet_directory_uri() . '/js/custom.js' );

    $js_translation_string = array(

        'title' => __( 'Let\'s keep in touch', 'newslsetter-domain' ),

        'name' =>  __( 'Name', 'newslsetter-domain' ),

        'otp_01' =>  __( 'By clicking on "Subscribe" you agree to receive news, offers and news of Salumi Pasini products. You can unsubscribe at any time by clicking on the link on the newsletter that we will send you.', 'newslsetter-domain' ),

        'otp_02' => __(' Read the complete information.', 'newslsetter-domain'),

        'subscribe' =>  __( 'Subscribe', 'newslsetter-domain' )

    );



    wp_localize_script( 'custom-js', 'newsletter_translate', $js_translation_string);



    // TRADUZIONI CARRELLO SCRIPT PER FARE IL CHECK SUL SUBTOTALE E VEDERE SE è MAGGIORI DI 29€



     $checkSubtotal_translation_string = array(

        'error_message_1' => __( 'We remind you that to proceed it is necessary to make a minimum purchase of € 29, missing €', 'checkSubtotal-domain' ),

        'error_message_2' => __( 'to your cart', 'checkSubtotal-domain' ),

        'shop_url' => __( '/en/store/', 'checkSubtotal-domain' ),

        'backtoshop_label' => __( 'Back to shop', 'checkSubtotal-domain' ),



    );



    wp_localize_script( 'custom-js', 'subtotal_translate', $checkSubtotal_translation_string);


    $readMoreProduct_translation_string = array(

        'read_more' => __( 'Read more', 'product-detail-domain' ),

        'close' => __( 'Close', 'product-detail-domain' ),



    );



    wp_localize_script( 'custom-js', 'readMoreProduct', $readMoreProduct_translation_string);





    $product = get_queried_object();

    $terms = get_the_terms( $product->ID , 'product_cat' );

    $category_link = get_category_link( $terms[0]->term_id );



    if (is_product()) {

        wp_add_inline_script( 'custom-js', 'const PRODUCT = ' . json_encode( array(

        'category_link' => $category_link

    ) ), 'before' );

    }



    // **********************



    wp_enqueue_script( 'custom-js', get_stylesheet_directory_uri() . '/js/custom.js', array( 'jquery' ), '1.0.0', true );

    wp_enqueue_script( 'slick-js', get_stylesheet_directory_uri() . '/slick/src/slick.min.js', array( 'jquery' ), '1.0.0', true );

    wp_enqueue_style ('slick-css', get_stylesheet_directory_uri() . '/slick/src/slick.css');

    wp_enqueue_style ('slick-themme-css', get_stylesheet_directory_uri() . '/slick/src/slick-theme.css');

    wp_enqueue_script( 'infinite-scroll-js', get_stylesheet_directory_uri() . '/infinite-scroll/js/infinite-scroll.pkgd.min.js', array ( 'jquery' ), 1.1, true);

    wp_enqueue_style ('infinite-scroll-js-css', get_stylesheet_directory_uri() . '/infinite-scroll/css/infinite-scroll.css');



}

add_action('wp_print_styles', 'add_custom_font');



//Rimuovere zoom woocommerce

function remove_image_zoom_support() {

    remove_theme_support( 'wc-product-gallery-zoom' );

}



// Function that will return our WordPress menu

function list_menu($atts, $content = null) {

	extract(shortcode_atts(array(

		'menu'            => '',

		'container'       => 'div',

		'container_class' => '',

		'container_id'    => '',

		'menu_class'      => 'menu',

		'menu_id'         => '',

		'echo'            => true,

		'fallback_cb'     => 'wp_page_menu',

		'before'          => '',

		'after'           => '',

		'link_before'     => '',

		'link_after'      => '',

		'depth'           => 0,

		'walker'          => '',

		'theme_location'  => ''),

		$atts));

	return wp_nav_menu( array(

		'menu'            => $menu,

		'container'       => $container,

		'container_class' => $container_class,

		'container_id'    => $container_id,

		'menu_class'      => $menu_class,

		'menu_id'         => $menu_id,

		'echo'            => false,

		'fallback_cb'     => $fallback_cb,

		'before'          => $before,

		'after'           => $after,

		'link_before'     => $link_before,

		'link_after'      => $link_after,

		'depth'           => $depth,

		'walker'          => $walker,

		'theme_location'  => $theme_location));

}

//Create the shortcode

add_shortcode("listmenu", "list_menu");



// Creo shortcode per sku dinamico al cambio di variazione

 function wc_product_sku_div() {

    global $product;



    if( !is_a('WC_Product', $product) ) {

        $product = wc_get_product( get_the_id() );

    }



    ## 1 - For variable products (and their variations)

    if (is_a($product, 'WC_Product') || is_subclass_of($product, 'WC_Product')) {

        if($product->is_type('variable') ) {

            ob_start(); // Starting buffering

            ?>

            <div class="widget" sp-sku=""></div>

            <script type="text/javascript">

            jQuery( function($){

                $('form.variations_form').on('show_variation', function( i, v ){



                    $( 'div.widget' ).attr( 'sp-sku', v.sku );

                    $( 'div.widget' ).text( v.sku );

                });

                $('form.variations_form').on('hide_variation', function(){

                    $( 'div.widget' ).attr( 'sp-sku', '' );

                    $( 'div.widget' ).text( v.sku );

                });

            });

            </script><?php



            return ob_get_clean(); // return the buffered content

        }

        ## 2 - For other products types

        else {

            return sprintf( '<div class="widget" sp-sku="%s"><span class="sku_simple">' .$product->get_sku(). '</span></div>', $product->get_sku() );

        }

    }

}



add_shortcode( 'product_sku_div', 'wc_product_sku_div');



// Stampo confezionamento

function show_confezionamento(){

global $product;



    if (! is_a('WC_Product', $product) ) {

        $product = wc_get_product( get_the_id() );

    }



    if (is_a($product, 'WC_Product') || is_subclass_of($product, 'WC_Product')) {

        if (!$product->is_type( 'simple' )){

            $attr = $product->get_attribute( 'pa_confezionamento' );

           ob_start();

            echo '<span id="pos_confezionamento">'. $attr .'</span>';

              return ob_get_clean();





        } else {

            $attr = $product->get_attribute( 'pa_confezionamento' );

            $attr2 = $product->get_attribute( 'pa_peso' );

            ob_start();

            echo '<span>'. $attr .' | '.$attr2.'</span>';

            return ob_get_clean();

        }

    }



}



add_shortcode("confezionamento", "show_confezionamento");





/* Il prezzo delle variazioni cambia automaticamente nel modulo prie divi */

add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );

function move_variations_single_price(){

    global $product, $post;



    if ( $product->is_type( 'variable' ) ) {

        // removing the variations price for variable products

        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );



        // Change location and inserting back the variations price

        add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );

    }

}



function replace_variation_single_price(){

    global $product;



    // Main Price

    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );

    $price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );



    // Sale Price

    $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );

    sort( $prices );

    $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );



    if ( $price !== $saleprice && $product->is_on_sale() ) {

        $price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';

    }



    ?>

    <style>

        div.woocommerce-variation-price,

        div.woocommerce-variation-availability,

        div.hidden-variable-price {

            height: 0px !important;

            overflow:hidden;

            position:relative;

            line-height: 0px !important;

            font-size: 0% !important;

        }

    </style>

    <script>



    jQuery(document).ready(function($) {

        startValue = jQuery(".prodotto__prezzo > div > p.price").html()



        $('select').change( function(){

            setTimeout(function(){

                if($('input.variation_id').val() != ""){

                    if($('p.availability'))

                        $('p.availability').remove();

                    $('p.price').html(

                        $('div.woocommerce-variation-price > span.price').html()

                    ).append('<p class="availability">'+$('div.woocommerce-variation-availability').html()+'</p>');

                } else {

                    $('p.price').html(startValue);

                    if($('p.availability'))

                        $('p.availability').remove();

                }

            }, 100);

        });

    });

    </script>

    <?php

}



//migliorare la ricerca

function custom_remove_default_et_pb_custom_search() {

	remove_action( 'pre_get_posts', 'et_pb_custom_search' );

	add_action( 'pre_get_posts', 'custom_et_pb_custom_search' );

}

add_action( 'wp_loaded', 'custom_remove_default_et_pb_custom_search' );



function custom_et_pb_custom_search( $query = false ) {

	if ( is_admin() || ! is_a( $query, 'WP_Query' ) || ! $query->is_search ) {

		return;

	}



	if ( isset( $_GET['et_pb_searchform_submit'] ) ) {

		$postTypes = array();



		if ( ! isset($_GET['et_pb_include_posts'] ) && ! isset( $_GET['et_pb_include_pages'] ) ) {

            $postTypes = array( 'post' );

        }



		if ( isset( $_GET['et_pb_include_pages'] ) ) {

            $postTypes = array( 'page' );

        }



		if ( isset( $_GET['et_pb_include_posts'] ) ) {

            $postTypes[] = 'post';

        }



		/* BEGIN Add custom post types */

		$postTypes[] = 'product';

		/* END Add custom post types */



		$query->set( 'post_type', $postTypes );



		if ( ! empty( $_GET['et_pb_search_cat'] ) ) {

			$categories_array = explode( ',', $_GET['et_pb_search_cat'] );

			$query->set( 'category__not_in', $categories_array );

		}



		if ( isset( $_GET['et-posts-count'] ) ) {

			$query->set( 'posts_per_page', (int) $_GET['et-posts-count'] );

		}

	}

}

function custom_single_product_image_html( $html, $post_id ) {

    $post_thumbnail_id = get_post_thumbnail_id( $post_id );

    return get_the_post_thumbnail( $post_thumbnail_id, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );

}

add_filter('woocommerce_single_product_image_thumbnail_html', 'custom_single_product_image_html', 10, 2);



//badge nuovi prododtti

/**

 * @snippet       Add Inline Field Error Notifications @ WooCommerce Checkout

 * @how-to        Get CustomizeWoo.com FREE

 * @sourcecode    https://businessbloomer.com/?p=86570

 * @author        Rodolfo Melogli

 * @compatible    WooCommerce 3.5.4

 * @donate $9     https://businessbloomer.com/bloomer-armada/

 */



add_action( 'woocommerce_before_shop_loop_item_title', 'bbloomer_new_badge_shop_page', 3 );



function bbloomer_new_badge_shop_page() {

   global $product;

   $newness_days = 30;

   $created = strtotime( $product->get_date_created() );

   if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {

      echo '<span class="itsnew onsale" id="badge-novita" id="badge-novita">' . esc_html__( 'Novità!', 'woocommerce' ) . '</span>';

   }

}

add_action( 'woocommerce_before_shop_loop_item_title', 'badgelee', 3 );



function badgelee() {
$badge = pods_field_display( 'badgele' );
	if($badge == "si"){
		if((ICL_LANGUAGE_CODE=='it') !== false){
        echo '<span class="itsnew onsale" id="badge-limited" >' . esc_html__( 'edizione limitata', 'woocommerce' ) . '</span>';
		}
        if((ICL_LANGUAGE_CODE=='en') !== false){
        echo '<span class="itsnew onsale" id="badge-limited" >' . esc_html__( 'Limited Edition', 'woocommerce' ) . '</span>';
		}
	}

}
add_action( 'woocommerce_before_shop_loop_item_title', 'treperdue', 3 );



function treperdue() {
$badge = pods_field_display( 'treperdue' );
	if($badge == "si"){
		if((ICL_LANGUAGE_CODE=='it') !== false){
        echo '<div class="bubble"><div class="inside"><div class="inside-text">3x2</div></div></div>';
		}
        if((ICL_LANGUAGE_CODE=='en') !== false){
        echo '<span class="itsnew onsale" id="badge-limited" ><img src="/wp-content/uploads/sicurezza.png" /></span>';
		}
	}

}


//stampa forma in card delle varianti disponibili

add_filter( 'woocommerce_shop_loop_item_title', 'so58344618_variation_count' );

function so58344618_variation_count() {



    global $product;

    $price_html = $product->get_price_html();

    $id=$product->get_id();

    if ( $product->is_type( 'variable' ) ) {







        $variation_min_price = $product->get_variation_price('min',1);

		 //echo '<br/>$variation_min_price '.$variation_min_price;

		 $min_variation_price = $product->get_variation_regular_price( 'min',1);

		// echo '<br/>$min_variation_price '.wc_price($min_variation_price);

		 $available_variations = $product->get_available_variations();

		 //echo '<br/>variation_description '.$available_variations[0]['variation_description'];

		 //echo '<br/>display_price '.$available_variations[0]['display_price'];



		 foreach($available_variations as $available_variation)

		 {

			 if ($variation_min_price==$available_variation['display_price'])

			 {

			     echo '<span class="pa-confezionamento-attributo">'.$available_variation['variation_description'].'</span>';

			     $variations = $product->get_available_variations();

                 $count      = count( $variations );



                echo "<button class='vaiAlProdotto'>". __("View product", "TRADUZIONIFIN") ."</button></a><span class='product_pipe'>|</span><div class='product_loop_price_c'> $price_html</div>";



			 }

		 }



    }

    elseif($product->is_type( 'simple' ) )

    {

         $product_attributes = $product->get_attributes();

		 $term = get_term( $product_attributes['pa_confezionamento']['options'][0] );

		 $term_peso = get_term( $product_attributes['pa_peso']['options'][0] );

		 //var_dump($term->name);

		 echo '<span class="pa-confezionamento-attributo">'.$term->name.'</span>';

		  echo '<span class="pa-peso-attributo">'.$term_peso->name.'</span>';



        echo "<button class='vaiAlProdotto'>". __("View product", "TRADUZIONIFIN") ."</button></a><span class='product_pipe'>|</span><div class='product_loop_price_c'> $price_html</div>";

	}

}



// infinite scroll

function enqueue_parent_styles() {

    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

}



// pulsante quantità + -

add_action( 'woocommerce_after_quantity_input_field', 'ts_quantity_plus_sign' );





function ts_quantity_plus_sign() {

   echo '<button type="button" class="plus" >+</button>';

}



add_action( 'woocommerce_before_quantity_input_field', 'ts_quantity_minus_sign' );



function ts_quantity_minus_sign() {

   echo '<button type="button" class="minus" >-</button>';

}



/**

 * Attributes shortcode callback.

 */

function so_39394127_attributes_shortcode( $atts ) {



    global $product;



    if( ! is_object( $product ) || ! $product->has_attributes() ){

        return;

    }



    // parse the shortcode attributes

    $args = shortcode_atts( array(

        'attributes' => array_keys( $product->get_attributes() ), // by default show all attributes

    ), $atts );



    // is pass an attributes param, turn into array

    if( is_string( $args['attributes'] ) ){

        $args['attributes'] = array_map( 'trim', explode( '|' , $args['attributes'] ) );

    }



    // start with a null string because shortcodes need to return not echo a value

    $html = '';



    if( ! empty( $args['attributes'] ) ){



        foreach ( $args['attributes'] as $attribute ) {



            // get the WC-standard attribute taxonomy name

            $taxonomy = strpos( $attribute, 'pa_' ) === false ? wc_attribute_taxonomy_name( $attribute ) : $attribute;



            if( taxonomy_is_product_attribute( $taxonomy ) ){



                // Get the attribute label.

                $attribute_label = wc_attribute_label( $taxonomy );



                // Build the html string with the label followed by a clickable list of terms.

                // Updated for WC3.0 to use getters instead of directly accessing property.

                $html .= get_the_term_list( $product->get_id(), $taxonomy, '<li>' , '<li>' , '</li>' );

            }



        }



        // if we have anything to display, wrap it in a <ul> for proper markup

        // OR: delete these lines if you only wish to return the <li> elements

        if( $html ){

            $html = '<ul class="product-attributes">' . $html . '</ul>';

        }



    }



    return $html;

}

add_shortcode( 'display_attributes', 'so_39394127_attributes_shortcode' );



// Add "Add to Cart" buttons in Divi shop pages

    add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );



add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );

/**

 * custom_woocommerce_template_loop_add_to_cart

*/

function custom_woocommerce_product_add_to_cart_text() {

	global $product;

	$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

	$text = "Aggiungi al carrello";

	if (preg_match('/\/en\//', $url)) {

	$text = "Add to cart";

} elseif (preg_match('/\/fr\//', $url)) {

	$text = "Ajouter au panier";

} elseif (preg_match('/\/de\//', $url)) {

	$text = "Details ansehen";

}

	$product_type = $product->product_type;



	switch ( $product_type ) {

		case 'external':

			return __( $text, 'woocommerce' );

		break;

		case 'grouped':

			return __( $text, 'woocommerce' );

		break;

		case 'simple':

			return __( $text, 'woocommerce' );

		break;

		case 'variable':

			return __( $text, 'woocommerce' );

		break;

		default:

			return __( $text, 'woocommerce' );

	}



}



/*- cambio stringa per ordinamento shop--*/

add_filter( 'woocommerce_catalog_orderby', 'misha_rename_default_sorting_options' );



function misha_rename_default_sorting_options( $options ){



	$options[ 'menu_order' ] = __('Season choice', 'relevance_order'); // rename

	$options[ 'date' ] = __('New products', 'relevance_order'); // rename

	$options[ 'price-desc' ] = __('Price: high-low', 'relevance_order'); // rename

	$options[ 'price' ] = __('Price: low-high', 'relevance_order'); // rename


	return $options;

}




// Edit WooCommerce dropdown menu item of shop page//

// Options: menu_order, popularity, rating, date, price, price-desc


/*
function my_woocommerce_catalog_orderby( $orderby ) {

    unset($orderby["price"]);

    return $orderby;

}

add_filter( "woocommerce_catalog_orderby", "my_woocommerce_catalog_orderby", 20 );
*/


/* Rimuovo popolarità */
/**
* @snippet       Remove Sorting Option @ WooCommerce Shop
* @how-to        Get CustomizeWoo.com FREE
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.8
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/

add_filter( 'woocommerce_catalog_orderby', 'bbloomer_remove_sorting_option_woocommerce_shop' );

function bbloomer_remove_sorting_option_woocommerce_shop( $options ) {
   unset( $options['popularity'] );
   return $options;
}



/* Blog thumbnail e immagini ricerca*/

function wpt_blog_thumbnail_width( $width ) {

	return 480; //blog thumbnail width in pixels

}

add_filter( 'et_pb_blog_image_width', 'wpt_blog_thumbnail_width');



function wpt_blog_thumbnail_height( $height ) {

	return 480; //blog thumbnail height in pixels

}

add_filter( 'et_pb_blog_image_height', 'wpt_blog_thumbnail_height');



// Title Removal from WordPress image

add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text');

function remove_image_text( $attr ) {

unset($attr['title']);

return $attr;

}



// cambio stringa carrello vuoto



remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );

add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );



function custom_empty_cart_message() {

    $html  = '<div class="woocommerce-empty-cart"><p class="cart-empty">';

    $html .= wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Oops, it seems you do not have any product on your cart', 'woocommerce' ) ) );

    echo $html . '</p></div>';

}





// phone required

add_filter( 'woocommerce_shipping_fields', 'force_wc_phone_field');

function force_wc_phone_field( $fields ) {

    $fields['shipping_phone']['required'] = true;

    return $fields;

}

/* Aggiungo lo shorcode per poter visualizzare l'utente registrato in woocommerce */

function add_shortcode2(){
    $user_info = wp_get_current_user();
	if(isset($user_info)){
		$userData = $user_info->first_name;
		return $userData;
	}
}

add_shortcode( 'userdata', 'add_shortcode2' );

 /*      ___     -._
            `-. """--._ `-.
               `.      "-. `.
 _____           `.       `. \
`-.   """---.._    \        `.\
   `-.         "-.  \         `\
      `.          `-.\          \_.-""""""""--._
        `.           `                          "-.
          `.                                       `.    __....-------...
--..._      \                                       `--"""""""""""---..._
__...._"_-.. \                       _,                             _..-""
`-.      """--`           /       ,-'/|     ,                   _.-"
   `-.                 , /|     ,'  / |   ,'|    ,|        _..-"
      `.              /|| |    /   / |  ,'  |  ,' /        ----"""""""""_`-
        `.            ( \  \      |  | /   | ,'  //                 _.-"
          `.        .'-\/'""\ |  '  | /  .-/'"`\' //            _.-"
    /'`.____`-.  ,'"\  ''''?-.V`.   |/ .'..-P''''  /"`.     _.-"
   '(   `.-._""  ||(?|    /'   >.\  ' /.<   `\    |P)||_..-"___.....---
     `.   `. "-._ \ ('   |     `8      8'     |   `) /"""""    _".""
       `.   `.   `.`.b|   `.__            __.'   |d.'  __...--""
         `.   `.   ".`-  .---      ,-.     ---.  -'.-""
           `.   `.   ""|      -._      _.-      |""
             `.  .-"`.  `.       `""""'       ,'
               `/     `.. ""--..__    __..--""
                `.      /7.--|    """"    |--.__
                  ..--"| (  /'            `\  ` ""--..
               .-"      \\  |""--.    .--""|          "-.
              <.         \\  `.    -.    ,'       ,'     >
             (P'`.        `%,  `.      ,'        /,' .-"'?)
             P    `. \      `%,  `.  ,'         /' .'     \
            | --"  _\||       `%,  `'          /.-'   .    )
            |       `-.""--..   `%..--"""\\"--.'       "-  |
            \          `.  .--"""  "\.\.\ \\.'       )     |

 */

 add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_catalog_ordering_args', 20, 1 );

function custom_catalog_ordering_args( $args ) {

    if( $_GET['orderby'] == 'date' )
        $args['order'] = 'DESC'; // Set order by DESC

    return $args;
}


function custom_user_redirect($redirect, $user){
    $redirect = wp_get_referer() ? wp_get_referer() : home_url();
	if(is_user_logged_in()){
		if ( in_array( 'customer', (array) $user->roles ) && $woocommerce->cart->cart_contents_count>0) {
    			$redirect = get_checkout_url();
		}
		$redirect = get_permalink( wc_get_page_id( 'shop' ) );
	}
    return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'custom_user_redirect',10, 2 );


function notification_bar(){
	if((ICL_LANGUAGE_CODE=='it') !== false)
	/*$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
	if (str_contains($actual_link, '/bresup/') or str_contains($actual_link, '/come-utilizzare-prosciutto-crudo-avanzato/'))*/ {
	echo '<div class="notification_bar" style="position: fixed; left: 0; top: 0; width: 100%; z-index: 9999999 !important; height:50px; text-align: center; font-weight: 600; background-color: #cf8f00; padding-top: 5px; padding-bottom: 5px; color: #fff;">10% Rabatt auf alle Produkte auf Website (außer Angebote) - nur mit dem Code BLACKF22 - bis zum 28/11!</div>';
echo '<style> header {margin-top: 50px;} </style>';
echo '<style> #header-desktop {margin-top: 30px;} </style>';

}
}

add_action( 'wp_body_open', 'notification_bar' );



// =========================================================================
// GOOGLE TAG MANAGER - <head>
// =========================================================================
function add_gtag_to_head() { ?>
    <!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-M5QPSQ4');</script>
<!-- End Google Tag Manager -->
<meta name="facebook-domain-verification" content="y2uqulujc83gybp6oa6f6zfirc2gyf" />
<!-- TrustBox script -->
<script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js" async></script>
<!-- End TrustBox script -->
<?php }
add_action('wp_head', 'add_gtag_to_head');


// =========================================================================
// GOOGLE TAG MANAGER - <body>
// =========================================================================
function add_gtag_to_body() { ?>
    <!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M5QPSQ4"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<?php }
add_action('wp_body_open', 'add_gtag_to_body');

// =========================================================================
// DATA LAYER FOR TAG MANAGER - WOOCOMMERCE "PURCHASE" THANK YOU PAGE - LUNA
// =========================================================================
function push_to_datalayer($order_id){

    $page_id_it = 43; // ID = 43 > THANK YOU PAGE IT
    $page_id_en = 9846; // ID = 9846 > THANK YOU PAGE EN
    $page_id_fr = 9849; // ID = 9849 > THANK YOU PAGE FR
    $page_id_de = 11486; // ID = 11486 > THANK YOU PAGE DE
    if (is_page($page_id_it) || is_page($page_id_en) || is_page($page_id_fr) || is_page($page_id_de)) {

        $order_id = $_GET['order'];

        if (isset($order_id) && $order_id != "") {

          $order = wc_get_order( $order_id );
          ?>
          <script type='text/javascript'>
          window.dataLayer = window.dataLayer || [];
                window.dataLayer.push({
                     // 'event' : 'transaction',
                     event: 'gtm4wp.orderCompletedEEC',
                     'ecommerce' : {
                         'purchase' : {
                             'actionField' : {
                                 'id': '<?php echo $order->get_order_number(); ?>',
                                 'affiliation': '<?php echo get_option("blogname"); ?>',
                                 'revenue' : '<?php echo number_format($order->get_subtotal(), 2, ".", ""); ?>',
                                 'tax': '<?php echo number_format($order->get_total_tax(), 2 ,".", ""); ?>',
                                 'shipping': '<?php echo number_format($order->calculate_shipping(), 2 , ".", ""); ?>',
                                 <?php if($order->get_used_coupons()) : ?>
                                  'coupon' : '<?php echo implode("-", $order->get_used_coupons()); ?>'
                                 <?php endif; ?>
                             },
                                 'products': [
                                        <?php
                                         foreach ( $order->get_items() as $key => $item ) :
                                            $product = $order->get_product_from_item($item);
                                            $variant_name = ($item['variation_id']) ? wc_get_product($item['variation_id']) : '';
                                        ?>
                                    {
                                        'name' : "<?php echo $item['name']; ?>",
                                        'id' : '<?php echo $item['product_id']; ?>',
                                        'price' : '<?php echo number_format($order->get_line_subtotal($item), 2, ".", ""); ?>',
                                        'brand' : '',
                                        'category' : '<?php echo strip_tags($product->get_categories(', ', '', '')); ?>',
                                        'variant' : '<?php echo ($variant_name) ? implode("-" , $variant_name->get_variation_attributes()) : ''; ?>',
                                        'quantity' : <?php echo $item['qty']; ?>,
                                        'coupon' : ''
                                    },
                                <?php endforeach; ?>
                                 ]
                             }

                         }
                     });
        </script>

      <?php }
    }
}
add_action('wp_footer', 'push_to_datalayer');

add_action('wp_head', 'mega_menu_de');
	function mega_menu_de(){
		if((ICL_LANGUAGE_CODE=='de') !== false) {
			echo  '<style> .megamenu-container>.col-megamenu {flex: 0 0 40%;} </style>';
												}

}



// ======================================================================
// ESCLUDI DALLA RICERCA I PRODOTTI CON VISIBILITA' SETTATA SU "NASCOSTI"
// ======================================================================
add_action('pre_get_posts', 'exclude_hidden_search_query_pre');

function exclude_hidden_search_query_pre($query) {
    if ($query->is_search() && $query->is_main_query()) {
        $tax_query = $query->get('tax_query', array());

        $tax_query[] = array(
            'taxonomy' => 'product_visibility',
            'field'    => 'name',
            'terms'    => 'exclude-from-catalog',
            'operator' => 'NOT IN',
        );

        $query->set('tax_query', $tax_query);
    }
}
add_action( 'woocommerce_login_form_end', 'bbloomer_actual_referrer' );
 
function bbloomer_actual_referrer() {
   if ( ! wc_get_raw_referer() ) return;
   echo '<input type="hidden" name="redirect" value="' . wp_validate_redirect( wc_get_raw_referer(), wc_get_page_permalink( 'myaccount' ) ) . '" />';
}

Youez - 2016 - github.com/yon3zu
LinuXploit