• Gelöst ONEM

    (@grafikhouse)


    Vielleicht kann mir da jemand helfen.

    Wie wird der Code korrekt aufgebaut?

    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>';

            }

        }

    }
Ansicht von 16 Antwort (von insgesamt 16)
  • Moderator threadi

    (@threadi)

    Claude wie auch jede andere KI kann ein prima Hilfsmittel sein. Wenn man sich damit Code erzeugen lässt, sollte man diesen jedoch nicht 1:1, ungesehen und ungeprüft übernehmen. Man sollte den Code dann auch verstehen um später selbst dazu in der Lage zu sein ihn zu optimieren oder gar darin vorhandene Fehler durch KI-Halluzinationen auszuschließen.

    Beachte außerdem, dass dies ein Forum für die Hilfe durch Menschen für Menschen ist. Wenn jemand in KI eine Lösung für seine Herausforderungen finden würde, würde er die Frage nicht hier stellen.

Ansicht von 16 Antwort (von insgesamt 16)

Du musst angemeldet sein, um auf dieses Thema zu antworten.