Comment afficher des prix variables par défaut dans woocommerce?
-
-
Avez-vous déjà cherché sur le site?Have you already searched the site?
- 1
- 2013-10-10
- kaiser
-
J'ai répondu à une questiontrès similaire à cette réponseici: https://stackoverflow.com/questions/43617537/move-woocommerce-variation-price/49414293#49414293I answered a very similar question to this answer here: https://stackoverflow.com/questions/43617537/move-woocommerce-variation-price/49414293#49414293
- 0
- 2018-03-21
- Lucas Bustamante
-
2 réponses
- votes
-
- 2013-10-10
Lafonction
woocommerce_template_single_price()
gérant l'affichage duprix "normal"estenfichable,ce qui signifie qu'ellepeut être remplacéeen lemettant dans votrefunctions.php
://override woocommerce function function woocommerce_template_single_price() { global $product; if ( ! $product->is_type('variable') ) { woocommerce_get_template( 'single-product/price.php' ); } }
Celafonctionne car dans
woocommerce-template.php
lesfonctions sont lancées comme ceci:if ( ! function_exists( 'woocommerce_template_single_price' ) ) { function woocommerce_template_single_price() { woocommerce_get_template( 'single-product/price.php' ); } }
Comme vouspouvez le voir,le conditionnel dit si lafonctionn'existepas ,mais lafonctionexiste déjà. Celui quenous avonsmis dans le
functions.php
sera utilisé,carilest lancéplustôt.Pour afficher leprix de la variante lorsqu'une seulepage deproduit avec unproduit variableest chargée,vous devez sélectionner une variante deproduitpar défaut sur lapage demodification duproduit.
The function
woocommerce_template_single_price()
handling the display of the "normal" price is pluggable, which means it can be overridden putting this into yourfunctions.php
://override woocommerce function function woocommerce_template_single_price() { global $product; if ( ! $product->is_type('variable') ) { woocommerce_get_template( 'single-product/price.php' ); } }
This works because in
woocommerce-template.php
the functions gets initiated like this:if ( ! function_exists( 'woocommerce_template_single_price' ) ) { function woocommerce_template_single_price() { woocommerce_get_template( 'single-product/price.php' ); } }
As you can see the conditional says if the function not exists, but the function already exists. The one we put into the
functions.php
will be used, because it is initiated earlier.To show the the variation price when a single product page with a variable product is loaded, you have to select a default product variation on the product edit page.
-
- 2016-02-20
J'utilise lethème "Porto"et j'ai aussi ceproblème. Vouspouvez résoudre leproblème,en mettant ce code dans votre
functions.php
àpartir de votrethèmeenfant:// Cheapest Price add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); function wc_wc20_variation_price_format( $price, $product ) { // Main Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( '%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( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); if ( $price !== $saleprice ) { $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>'; } return $price; }
Que votreprix ressemble à unprix uniqueet que c'est leprix lemoins cher de votreproduit variable. Çamarche. Je l'ai utilisé.
I'm using the "Porto" Theme and haved this problem too. You can solve the problem, putting this code into your
functions.php
from your child theme:// Cheapest Price add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); function wc_wc20_variation_price_format( $price, $product ) { // Main Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( '%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( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); if ( $price !== $saleprice ) { $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>'; } return $price; }
Than your price looks like a single price and it the cheapest price from your variable product. It works. I've used it.
Je souhaite afficher leprix variablepar défaut dans l'onglet "àpartir duprix" de lapageproduit unique.etne pas avoir leprix de départ.
Ilest déroutantpour l'acheteur de voir unprix "àpartir de"puisen dessous unprixpour chaque variante,qui change unefois qu'une varianteest choisie.
voir l'image ci-jointe
Donc,au lieu d'avoir à desensembles de champs deprix,je veuxen afficher un seul oùil s'agit d'unproduit unique ou variable.