";
}
}
add_action( 'woocommerce_single_product_summary', 'add_soumission_button' , 40 );
function add_soumission_button() {
global $product; // this may not be necessary as it should have pulled the object in already
$lang=qtrans_getLanguage();
if ($lang=="fr") {$button="Demander le prix";}
else {$button="Get a Quote";}
//Si le produit est en rupture de stock, on affiche :
if ( !$product->is_in_stock() ) {
if ($lang=="fr") {$button="Demander ce qui s'en vient";}
else {$button="Ask for the upcoming machines";}
}
echo ''.$button.'';
?>
}
function priyan_sh_woocommerce_structured_data_product( $markup, $product ) {
if (empty($markup['mpn']))
$markup['mpn'] = $markup['sku'];
if (empty($markup['brand']))
//$markup['brand'] = 'Metfab';
$markup['brand'] = array(
'@type'=> 'Brand',
'name'=> 'Metfab'
);
if (empty($markup['aggregateRating']))
$markup['aggregateRating'] = array(
'@type' => 'AggregateRating',
'ratingValue' => 5,
'reviewCount' => 1,
);
if (empty($markup['review']))
$markup['review'] = array(
'@type'=> 'Review',
'reviewRating'=> [
'@type'=> 'Rating',
'ratingValue'=> '5',
'bestRating'=> '5'
],
'author'=> [
'@type'=> 'Person',
'name'=> 'Metfab Customer'
]
);
return $markup;
};
add_filter( 'woocommerce_structured_data_product', 'priyan_sh_woocommerce_structured_data_product', 10, 2 );
function yikes_woocommerce_direct_link_to_product_tabs() {
if( is_product() ) {
?>
}
}
add_action( 'wp_footer', 'yikes_woocommerce_direct_link_to_product_tabs', 100 );
// Ajouter description courte sur les archives
add_action( 'woocommerce_after_shop_loop_item_title', 'output_product_excerpt', 35 );
function output_product_excerpt() {
global $post;
global $product;
// echo '
'.wp_trim_words($post->post_excerpt,20).'
';
//
'.$post->post_title.'
/*if(is_archive()) {
echo '
'.$post->post_excerpt.'
'.$post->post_title.'
';
}*/
if(is_archive()) {
echo '
'.$post->post_excerpt.'
';
}
}
add_action( 'woocommerce_after_shop_loop_item', 'zone_boutons', 35 );
function zone_boutons() {
global $post;
echo '';
}
function get_qTrans_Trad($text) {
$language=qtrans_getLanguage();
if ($language!=="") {$language="EN";}
preg_match('/[:'.$language.'](.*?)[:]/', $text, $matches);
return $matches[0];
}
// Modifier données structurées
// Code original dans public_html/wp-content/plugins/woocommerce/includes\class-wc-structured-data.php
function cl_product_delete_meta_price( $product = null ) {
if ( ! is_object( $product ) ) {
global $product;
}
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
if ( '' !== $product->get_price() ) {
$shop_name = get_bloginfo( 'name' );
$shop_url = home_url();
$currency = get_woocommerce_currency();
$price_valid_until = gmdate( 'Y-12-31', time() + YEAR_IN_SECONDS );
if ( $product->is_type( 'variable' ) ) {
$prices = $product->get_variation_prices();
$lowest = reset( $prices['price'] );
$highest = end( $prices['price'] );
$structured_price=wc_format_decimal( $lowest, wc_get_price_decimals() );
/*if ( $lowest === $highest ) {
$markup_offer = array(
'@type' => 'Offer',
'price' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
);
} else {
$markup_offer = array(
'@type' => 'AggregateOffer',
'lowPrice' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
'highPrice' => wc_format_decimal( $highest, wc_get_price_decimals() ),
);*/
}
else {
$structured_price=wc_format_decimal( $product->get_price(), wc_get_price_decimals() );
}
$structured_price=0;
// MODIF MERYLE
$stock_status = $product->get_stock_status();
$availability_status = 'OutOfStock'; // default, out of stock
if ($stock_status){
$availability_status = 'InStock';
$qty = $product->get_stock_quantity();
if ( ! ($qty > 0) ) {
$availability_status = 'PreOrder';
}
}
$availability_status="https://schema.org/".$availability_status;
$markup_offer = array(
'@type' => 'Offer',
'availability' => $availability_status,
'sku' => $product->get_sku(),
'image' => wp_get_attachment_url( $product->get_image_id() ),
'description' => $product->get_description(),
'priceCurrency' => $currency,
'price' => $structured_price,
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);
}
return $markup_offer;
}
add_filter( 'woocommerce_structured_data_product_offer', 'cl_product_delete_meta_price', 10, 2 );
// Cacher la catégorie par défaut uncategorised
add_filter( 'woocommerce_product_subcategories_args', 'custom_woocommerce_product_subcategories_args' );
function custom_woocommerce_product_subcategories_args( $args ) {
$args['exclude'] = get_option( 'default_product_cat' );
return $args;
}
// Afficher les catégories sans produit
add_filter( 'woocommerce_product_subcategories_hide_empty', 'hide_empty_categories', 10, 1 );
function hide_empty_categories ( $hide_empty ) {
$hide_empty = FALSE;
// You can add other logic here too
return $hide_empty;
}
//remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
//remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
//remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 5 );
//add_action( 'woocommerce_simple_add_to_cart', 'woocommerce_template_single_meta', 10);
//add_action( 'woocommerce_single_product_summary', 'add_compare_link', 65 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
/*
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 0 );
add_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
add_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
add_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
add_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );*/
add_filter( 'woocommerce_product_tabs', 'woo_add_new_product_tab' );
function woo_add_new_product_tab( $tabs ) {
/* Adds the new tab */
global $product;
$lang=qtrans_getLanguage();
//Si le produit est en rupture de stock, on affiche :
if ( !$product->is_in_stock() ) {
$tabs['soumission'] = array(
'title' => __( '[:fr]Demande d\'information[:en]Ask for information[:]', 'woocommerce' ),
'priority' => 550,
'callback' => 'woo_add_new_product_tab_content'
);
}
else {
$tabs['soumission'] = array(
'title' => __( '[:fr]Demande de prix[:en]Ask the price[:]', 'woocommerce' ),
'priority' => 550,
'callback' => 'woo_add_new_product_tab_content'
);
}
return $tabs; /* Return all tabs including the New Custom Product Tab to display */
}
function woo_add_new_product_tab_content() {
wc_get_template('single-product/tabs/soumission.php');
}
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['additional_information']['title'] = __('[:fr]Caractéristiques[:en]Specifications[:]'); // Rename the additional information tab
return $tabs;
}
/*
add_action( 'woocommerce_product_thumbnails', 'metfab_video_thumbnails', 50 );
function metfab_video_thumbnails() {
$videoID = get_post_meta($post->ID, 'product-videos', true);
$video = get_field('video');
//echo "video : ".$videoID;
// Check if there is in fact a video URL
if ($video) {
$video_tab=explode("v=", $video);
//print_r($video_tab);
$videoID=$video_tab[1];
$video_link = 'https://www.youtube.com/embed/'.$videoID;
echo '