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
/* 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
}
Alles anzeigen
Contact Form 7:
HTML
<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>
Alles anzeigen