Beiträge von Traxtar
-
-
Vielen Dank für den Hinweis :-)
Ich bekomme nun die aktive Variation ausgelesen und sogar die zugehörige Artikelnummer in der Konsole angezeigt.
Das Problem ist nur noch, die jQuery-Variable „vari.sku“ nach PHP „$artikelnr“ zu übertragen.
Hat jemand dazu eine Idee?PHP
Alles anzeigen<?php function product_enquiry_tab_form() { global $product; //If you want to have product ID also //$product_id = $product->id; $artikelnr = " "; $subject = "Anfrage zu ".$product->post->post_title; echo "<h2>".$subject."</h2>"; echo do_shortcode('[contact-form-7 id="1882" title="Kontaktformular 1"]'); ?> <script> (function($){ <?php if ($product->is_type( 'simple' )) { ?> // Einfaches Produkt $(".product_name").val("<?php echo $subject." (Art.-Nr.: ".$product->get_sku().")"; ?>"); <?php } elseif( $product->is_type( 'variable' ) ){ ?> // Variables Produkt $(".product_name").val("<?php echo $subject." Hauptartikel"; ?>"); // erster Aufruf $( ".variations_form" ).on( "woocommerce_variation_select_change", function () { // wechsel der Auswahloption console.log("change"); $(".product_name").val("<?php echo $subject." Hauptartikel"; ?>"); // wenn keine Variation ausgewählt wurde $( document ).ready( function($) { $( '.variations_form' ).each( function() { // when variation is found, do something $(this).on( 'found_variation', function( event, vari ) { // Variables Produkt wird als Objekt aufgerufen console.log(vari); // Zeigt Object in der Konsole console.log(vari.sku); // Zeigt Artikelnummer in der Konsole <?php $artikelnr = vari.sku; ?> // Qjuery nach PHP ??? $(".product_name").val("<?php echo $subject." (Art.-Nr.: ".$artikelnr.")"; ?>"); }); }); }); }); <?php } ?> })(jQuery); </script> <?php } ?> -
Hallo zusammen,
ich bräuchte mal eure Hilfe:
Auf der Produktseite habe ich neben "Beschreibung" und "Zusätzliche Informationen" einen neuen Reiter/Tab angelegt, auf dem ein Anfrageformular mit 'Contact Form 7' eingebunden ist. Nun möchte ich, dass in der Betreffzeile die Artikelnummer (SKU) mit angegeben wird. Bei einfachen Artikeln funktioniert es soweit einwandfrei. Jedoch habe ich noch Probleme damit, wenn ein Produkt mit Variationen ausgewählt wird. Hier sollte dann die SKU des ausgewählten Produkts angezeigt werden.
Für Hilfe oder Anregungen wäre ich sehr dankbar :-)functions.php:
PHP
Alles anzeigen/* Anfrageformular im Tab auf Produktseite */ add_filter( 'woocommerce_product_tabs', 'product_enquiry_tab' ); function product_enquiry_tab( $tabs ) { $tabs['anfrage_tab'] = array( 'title' => __( 'Anfrage', 'woocommerce' ), 'priority' => 50, 'callback' => 'product_enquiry_tab_form' ); return $tabs; } function product_enquiry_tab_form() { global $product; //If you want to have product ID also //$product_id = $product->id; $subject = "Anfrage zu ".$product->post->post_title; echo "<h2>".$subject."</h2>"; echo do_shortcode('[contact-form-7 id="1" title="Kontaktformular 1"]'); ?> <script> (function($){ <?php if ($product->is_type( 'simple' )) { ?> $(".product_name").val("<?php echo $subject." (Art.-Nr.: ".$product->get_sku().")"; ?>"); <?php } elseif( $product->is_type( 'variable' ) ){ $available_variations = $product->get_available_variations(); foreach ($available_variations as $key => $value) { ?> $(".product_name").val("<?php echo $subject." (Art.-Nr.: ".$value['sku'].")"; ?>"); <?php } } ?> })(jQuery); </script> <?php }
Contact Form 7:HTML
Alles anzeigen<table style="width:100%"> <tr> <td colspan="2"><label class="product_subject"> [text your-subject class:product_name] </label></td> </tr> <tr> <td><label> [text* your-name placeholder"Ihr Name"] </label></td> <td><label> [email* your-email placeholder"E-Mail-Adresse"] </label></td> </tr> <tr> <td colspan="2"><label> [textarea* your-message placeholder"Ihre Nachricht"] </label></td> </tr> <tr> <td>[submit "Senden"]</td> </tr> </table>