Favicon BulgaWeb

Produit WooCommerce fonctions

Mis à jour le dimanche 9 août 2020
Temps approximatif de lecture : 3 minutes

En cours d’élaboration, doit être vérifié et complété !

Vous pouvez retrouvez des références ici Hooks et ici pour les produits seuls

Titre

<?php
global $product;
$product = wc_get_product( id );  //archive seulement
echo '<div class="woo-title"><h2>' . $product->get_title() . '</h2></div>';
?>

Permaliens

echo 'Lien : ' . get_permalink( $product->get_id() ) ;

Image principale

ATTENTION dans ce cas les badges ne sont pas récupérés

<?php
the_post_thumbnail(); // Without parameter ->; Thumbnail
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'medium_large' ); // Medium-large resolution (default 768px x no height limit max)
the_post_thumbnail( 'large' ); // Large resolution (default 1024px x 1024px max)
the_post_thumbnail( 'full' ); // Original image resolution (unmodified)
the_post_thumbnail( array( 100, 100 ) ); // Other resolutions (height, width)
?>

Galerie

Fonction avec divers mode de récupération des images de la galerie d'un produit. Intégration assez aisée avec Swiper (à venir).

<?php
  global $product;
 $attachment_ids = $product->get_gallery_attachment_ids();

foreach( $attachment_ids as $attachment_id ) 
{
  //Get URL of Gallery Images - default wordpress image sizes
  echo $Original_image_url = wp_get_attachment_url( $attachment_id );
  echo $full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0];
  echo $medium_url = wp_get_attachment_image_src( $attachment_id, 'medium' )[0];
  echo $thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' )[0];
  
  //Get URL of Gallery Images - WooCommerce specific image sizes
  echo $shop_thumbnail_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_thumbnail' )[0];
  echo $shop_catalog_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_catalog' )[0];
  echo $shop_single_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_single' )[0];
  
  //echo Image instead of URL
  echo wp_get_attachment_image($attachment_id, 'full');
  echo wp_get_attachment_image($attachment_id, 'medium');
  echo wp_get_attachment_image($attachment_id, 'thumbnail');
  echo wp_get_attachment_image($attachment_id, 'shop_thumbnail');
  echo wp_get_attachment_image($attachment_id, 'shop_catalog');
  echo wp_get_attachment_image($attachment_id, 'shop_single');
}
?>

Récupérer les catégories des produits

global $product;

$product_cats_ids = wc_get_product_term_ids( $product->get_id(), 'product_cat' );
foreach( $product_cats_ids as $cat_id ) {
    $term = get_term_by( 'id', $cat_id, 'product_cat' );

    echo $term->name;
}

Insérer un attribut

function oxychild_woo_attribute(){
    global $product;
    $bui = $product->get_attribute( 'pa_pena' );
    echo '<div class="bu1_attribute">' . $bui . '</div>';
}
//add_action( 'woocommerce_shop_loop_item_title', 'bui_woo_attribute', 05 );
//add_action('woocommerce_single_product_summary', 'cw_woo_attribute', 25);

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Suite à la monétisation des mes postes sur un site externe (https://oxyhowto.com/more_hows-categories/french/) sans mon autorisation, les postes sont uniquement visibles avec un compte.
Copyright © 2019 - 2023 Bulgaweb
 | 
Développé par BulgaWeb
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram