File Manager

Current Path : /webspace/www.beetasty.be/html/wp-content/themes/Divi-child/
Upload File :
Current File : //webspace/www.beetasty.be/html/wp-content/themes/Divi-child/functions.php

<?php
/**
** activation theme
**/
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

/* if(!is_admin()) {
	add_filter( 'script_loader_tag', 'add_defer', 10, 2 );
	function add_defer( $tag, $handle ) {
	    return str_replace( ' src', ' defer src', $tag );
	}
}*/



/**
 * Remove the generated product schema markup from Product Category and Shop pages.
 */
function wc_remove_product_schema_product_archive() {
	remove_action( 'woocommerce_shop_loop', array( WC()->structured_data, 'generate_product_data' ), 10, 0 );
}
add_action( 'woocommerce_init', 'wc_remove_product_schema_product_archive' );

 

/**
** customisation de wpsl 
**/
add_filter( 'wpsl_listing_template', 'custom_listing_template' );

function custom_listing_template() {

    global $wpsl, $wpsl_settings;
    
    $listing_template = '<li data-store-id="<%= id %>">' . "\r\n";
    $listing_template .= "\t\t" . '<div class="wpsl-store-location">' . "\r\n";
    $listing_template .= "\t\t\t" . '<p><%= thumb %>' . "\r\n";
    $listing_template .= "\t\t\t\t" . wpsl_store_header_template( 'listing' ) . "\r\n"; // Check which header format we use
    $listing_template .= "\t\t\t\t" . '<span class="wpsl-street"><%= address %></span>' . "\r\n";
    $listing_template .= "\t\t\t\t" . '<% if ( address2 ) { %>' . "\r\n";
    $listing_template .= "\t\t\t\t" . '<span class="wpsl-street"><%= address2 %></span>' . "\r\n";
    $listing_template .= "\t\t\t\t" . '<% } %>' . "\r\n";
    $listing_template .= "\t\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n"; // Use the correct address format

    if ( !$wpsl_settings['hide_country'] ) {
        $listing_template .= "\t\t\t\t" . '<span class="wpsl-country"><%= country %></span>' . "\r\n";
    }

    $listing_template .= "\t\t\t" . '</p>' . "\r\n";
    
   // Include the opening hours, unless they are set to hidden on the settings page.
    if ( !$wpsl_settings['hide_hours'] ) {
        $listing_template .= "\t\t\t" . '<% if ( hours ) { %>' ;
        $listing_template .= "\t\t\t" . '<p><%= hours %></p>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
    }

    // Show the phone, fax or email data if they exist.
    if ( $wpsl_settings['show_contact_details'] ) {
        $listing_template .= "\t\t\t" . '<p class="wpsl-contact-details">' . "\r\n";
        $listing_template .= "\t\t\t" . '<% if ( phone ) { %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<span><strong>' . esc_html( $wpsl->i18n->get_translation( 'phone_label', __( 'Phone', 'wpsl' ) ) ) . '</strong>: <%= formatPhoneNumber( phone ) %></span>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% if ( fax ) { %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<span><strong>' . esc_html( $wpsl->i18n->get_translation( 'fax_label', __( 'Fax', 'wpsl' ) ) ) . '</strong>: <%= fax %></span>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% if ( email ) { %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<span><strong>' . esc_html( $wpsl->i18n->get_translation( 'email_label', __( 'Email', 'wpsl' ) ) ) . '</strong>: <%= email %></span>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $listing_template .= "\t\t\t" . '</p>' . "\r\n";
    }

    $listing_template .= "\t\t\t" . wpsl_more_info_template() . "\r\n"; // Check if we need to show the 'More Info' link and info
    $listing_template .= "\t\t" . '</div>' . "\r\n";
    $listing_template .= "\t\t" . '<div class="wpsl-direction-wrap">' . "\r\n";

    if ( !$wpsl_settings['hide_distance'] ) {
        $listing_template .= "\t\t\t" . '<%= distance %> ' . esc_html( $wpsl_settings['distance_unit'] ) . '' . "\r\n";
    }

    $listing_template .= "\t\t\t" . '<%= createDirectionUrl() %>' . "\r\n"; 
    $listing_template .= "\t\t" . '</div>' . "\r\n";
    $listing_template .= "\t" . '</li>';

    return $listing_template;
}

//Shortcode to show the module
//https://www.creaweb2b.com/woocommerce-personnaliser-page-de-categorie-divi-builder/
function showmodule_shortcode($moduleid) {
extract(shortcode_atts(array('id' =>'*'),$moduleid)); 
return do_shortcode('[et_pb_section global_module="'.$id.'"][/et_pb_section]');
}
add_shortcode('showmodule', 'showmodule_shortcode');

/**
 * Show a message at the cart/checkout displaying
 * how much to go for free shipping.
 */
function my_custom_wc_free_shipping_notice() {
	if ( ! is_cart() && ! is_checkout() ) { // Remove partial if you don't want to show it on cart/checkout
		return;
	}
	$packages = WC()->cart->get_shipping_packages();
	$package = reset( $packages );
	$zone = wc_get_shipping_zone( $package );
	$cart_total = WC()->cart->get_displayed_subtotal();
	if ( WC()->cart->display_prices_including_tax() ) {
		$cart_total = round( $cart_total - ( WC()->cart->get_discount_total() + WC()->cart->get_discount_tax() ), wc_get_price_decimals() );
	} else {
		$cart_total = round( $cart_total - WC()->cart->get_discount_total(), wc_get_price_decimals() );
	}
	foreach ( $zone->get_shipping_methods( true ) as $k => $method ) {
		$min_amount = $method->get_option( 'min_amount' );
		if ( $method->id == 'free_shipping' && ! empty( $min_amount ) && $cart_total < $min_amount && $cart_total != 0) {
			$remaining = $min_amount - $cart_total;
			wc_add_notice( sprintf( __('Plus que %s pour b&eacute;n&eacute;ficier de la livraison <u>gratuite</u> !','Divi'), wc_price( $remaining ) ) );
		}
	}
}
add_action( 'wp', 'my_custom_wc_free_shipping_notice' );

// This code adds "Add to Cart" buttons to a page displaying shop loop
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

/* Indiquer la rupture de stock */
add_action( 'woocommerce_before_shop_loop_item_title', 'wpm_display_sold_out_loop_woocommerce' );// On l'affiche sur la page boutique
add_action( 'woocommerce_single_product_summary', 'wpm_display_sold_out_loop_woocommerce' );// On l'affiche sur la page du produit seul

 
function wpm_display_sold_out_loop_woocommerce() {
    global $product;
 	//Si le produit est en rupture de stock, on affiche :
    if ( !$product->is_in_stock() ) {
        echo '<span class="soldout">' . __( 'Rupture de stock', 'woocommerce' ) . '</span>';
    }
} 

// Enqueue Your Font
// https://stackoverflow.com/questions/55223026/preload-woocommerce-star-woff-font
function my_queue_items() {
wp_enqueue_style( 'rating-stars', '/wp-content/plugins/woocommerce/assets/fonts/star.woff', array(), null );
}
add_action( 'wp_enqueue_scripts', 'my_queue_items', 99 );

// Add Crossorigin Attribute To Your Font
function style_attributes( $html, $handle ) {
if ( 'rating-stars' === $handle ) {
return str_replace( "media='all'", "media='all' crossorigin='anonymous'", $html );
}
return $html;
}
add_filter( 'style_loader_tag', 'style_attributes', 10, 2 );

// Montant minimum de commande
// https://wpchannel.com/woocommerce/tutoriels-woocommerce/montant-minimum-woocommerce-commande/
add_action( 'woocommerce_after_checkout_validation', 'mgris_minimum_order', 10, 2);
function mgris_minimum_order( $fields, $errors ) {
	global $woocommerce;
	// Modifier la variable $minorder par votre montant minimum.
	$minorder = 12;
	$panier = $woocommerce->cart->subtotal;

	if($panier < $minorder) {
		$errors->add( 'validation', sprintf(__('Désolé, pour pouvoir réaliser une commande en ligne, le montant de votre panier doit être supérieur à <strong>' . $minorder . '</strong> €. <br /><a href="%s">Retour à la boutique →</a><br />', 'textdomain'), get_permalink( wc_get_page_id('shop') ) ) );
	}
}

/******
/*** remove noindex from sitemap
/*** used for woocommerce special pages
/*****/
remove_action( 'wp_head', 'wc_page_noindex' );

/** cacher le poid et dimension expedition **/
add_filter('wc_product_enable_dimensions_display', '__return_false');

/**
 * Allow HTML in term (category, tag) descriptions
 */
foreach ( array( 'pre_term_description' ) as $filter ) {
	remove_filter( $filter, 'wp_filter_kses' );
	if ( ! current_user_can( 'unfiltered_html' ) ) {
		add_filter( $filter, 'wp_filter_post_kses' );
	}
}
 
foreach ( array( 'term_description' ) as $filter ) {
	remove_filter( $filter, 'wp_kses_data' );
}
/***
 * keep pages status in sync in diff lang.
 * */
add_filter( 'wpml_synchronize_post_status_post_types', function( $allowed_post_types ) { return array_merge($allowed_post_types, [ 'products' ]); } );

File Manager Version 1.0, Coded By Lucas
Email: hehe@yahoo.com