Auf WooCommerce möchte ich das Layout der variablen Seite eines einzelnen Produkts ändern. Denn wenn Sie ein variables Produkt haben, erhalten Sie diese Preisliste (unter dem Produkttitel) auf der Seite mit den variablen Produkten und auch auf der Shop-Seite.
Für mich ist die Standardmethode, den niedrigsten Preis des Produkts im Shop sowie die Produktseite anzuzeigen und diesen Preis entsprechend der Auswahl der Variablen des Benutzers zu ändern. Ich kann nicht glauben warum.
Ich kann die Preisspanne entfernen und den niedrigsten Preis mit diesem Code-Snippet anzeigen.
https://businessbloomer.com/disable-variable-product-price-range-woocommerce/
Andererseits ändert sich der niedrigste Preis nicht nach ausgewählten Variablen. Im variablen Produktlayout gibt es wieder zwei Preise. Dies ist mein aktuelles variables Seitenlayout
http://www.preorders.lk/product/beats-solo3-wireless-on-ear-headphones/
Kann also jemand helfen, die Preisspanne von der variablen Produktseite zu entfernen, und nur einen niedrigsten Preis (unter dem Produkttitel) des Produkts als Standard angeben. Daher sollte dieser Preis entsprechend den Variablen des jeweiligen Produkts geändert werden. Und dieser niedrigste Preis sollte auch auf der Shopseite angezeigt werden.
Hoffe das ist klar. Bitte lassen Sie mich wissen, wenn etwas unklar ist. Bitte beachten Sie das angehängte Bild für weitere Details.
Vielen Dank.
Neues, verbessertes Update im folgenden Thread (Juni 2018):
Preisbereich ersetzen, der die Standardabweichung behandelt, die in Woocommerce 3 angezeigt wird
Update (Dezember 2017): zu vermeiden, Probleme mit nicht variablen Produkten in einigen Themes und ein Fehler bei der Verfügbarkeit von Wiederholungen in einigen Themes
Hinweis: Einige Plugins wie der German Market oder einige Themes werden mit diesem Code nicht funktionieren, da sie ihre eigenen Änderungen in den Hooks oder in der HTML-Struktur vornehmen.
Das ist durchaus möglich.
jQuery
-Skripts ersetzen wir den variablen Preis (und zeigen die Verfügbarkeit des Lagers an), wenn wir den gewählten Variationspreis erhalten. Hier ist dieser Code:
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($) {
$('select').blur( 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>');
console.log($('input.variation_id').val());
} else {
$('p.price').html($('div.hidden-variable-price').html());
if($('p.availability'))
$('p.availability').remove();
console.log('NULL');
}
});
});
</script>
<?php
echo '<p class="price">'.$price.'</p>
<div class="hidden-variable-price" >'.$price.'</div>';
}
Code wird in jede PHP-Datei Ihres aktiven untergeordneten Designs (oder Designs) oder auch in eine beliebige Plugin-PHP-Datei eingefügt.
Dieser Code wurde getestet und funktioniert mit WooCommerce 3.2.x (sollte auch mit WooCommerce 2.6.x funktionieren)}
Sie können optional das CSS (
<style></style>
) in diestyles.css
-Datei Ihres aktiven untergeordneten Designs (oder aktiven Themes) verschieben und es dann aus dieser Funktion entfernen…
Verbunden:
Ich bin mir bewusst, dass ich hier einen alten Thread wiederbelebte, aber bei der Verwendung dieses Codes habe ich festgestellt, dass Sie sich bewusst sein müssen, dass mit diesem Code die Gefahr besteht, dass einzelne, nicht variable Preise von einigen Themen angezeigt werden:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
wird auf allen Produktseiten ausgelöst, unabhängig davon, ob es sich um ein variables Produkt handelt oder nicht.
Sie können die folgende Version verwenden, die einfach prüft, ob das aktuelle Produkt variabel ist oder nicht, bevor der Rest des Codes ausgeführt wird.
add_action( 'woocommerce_before_single_product', 'check_if_variable_first' );
function check_if_variable_first(){
if ( is_product() ) {
global $post;
$product = wc_get_product( $post->ID );
if ( $product->is_type( 'variable' ) ) {
// removing the price of variable products
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Change location of
add_action( 'woocommerce_single_product_summary', 'custom_wc_template_single_price', 10 );
function custom_wc_template_single_price(){
global $product;
// Variable product only
if($product->is_type('variable')):
// 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($) {
$('select').blur( function(){
if( '' != $('input.variation_id').val() ){
$('p.price').html($('div.woocommerce-variation-price > span.price').html()).append('<p class="availability">'+$('div.woocommerce-variation-availability').html()+'</p>');
console.log($('input.variation_id').val());
} else {
$('p.price').html($('div.hidden-variable-price').html());
if($('p.availability'))
$('p.availability').remove();
console.log('NULL');
}
});
});
</script>
<?php
echo '<p class="price">'.$price.'</p>
<div class="hidden-variable-price" >'.$price.'</div>';
endif;
}
}
}
}