PHP Code verschachteln
Verfasst: 07.06.2026 08:57
Hallo Leute
Da ich kein Programmierer bin weiss ich nicht wie das korrekt aufgebaut wird und mir jemand von euh Hilfestellung geben kann.
Da ich kein Programmierer bin weiss ich nicht wie das korrekt aufgebaut wird und mir jemand von euh Hilfestellung geben kann.
Code: Alles auswählen
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
function display_attribute_on_shop_page() {
global $product;
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'versandkosten';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Versandkosten: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'abholung';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Abholung: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'bett-matratzengroesse';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Bett / Matratzen Grösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'bh-groesse';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>BH Grösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'kleidergroesse-damen';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Kleidergrösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'kleidergroesse-herren';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Kleidergrösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'kleidergroesse-kinder-baby
';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Kleidergrösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'kleidergroesse-teenager';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Kleidergrösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'pc-monitor';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Grösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'schuhgroesse';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Grösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'display_attribute_on_shop_page', 5 );
// Überprüfen, ob das Produkt einfach ist
if ( $product->is_type( 'simple' ) ) {
$attribute_name = 'tv-groesse';
$attribute_values = $product->get_attribute( $attribute_name );
// Wenn das Attribut einen Wert hat, wird es ausgegeben
if ( ! empty( $attribute_values ) ) {
echo '<div class="shop-product-attribute">';
echo '<strong>Grösse: </strong>' . $attribute_values;
echo '</div>';
}
}
}]