Skip to content

Instantly share code, notes, and snippets.

@webonaut
Last active October 8, 2020 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webonaut/85622efe2b818e2d1442 to your computer and use it in GitHub Desktop.
Save webonaut/85622efe2b818e2d1442 to your computer and use it in GitHub Desktop.
WooCommerce - Eigene Produkt-Tabs und Felder für editierbare Tab-Inhalte mit Plugin ACF anlegen
// Beschreibung: Legt eigene Produkt-Tabs an, deren Inhalte mit Hilfe von Feldern des Plugins ACF editiert werden könnnen
// Speicherort: functions.php
// Quelle: http://docs.woothemes.com/document/editing-product-data-tabs/
// Beispiel: Mit folgendem Code werden 4 Reiter (=Tabs) angelegt (Reiter Programm, Reiter Highlights, Reiter Unterkunft und Reiter Leistungen;
// die Inhalte der einzelnen Tabs können im Wordpress-Backend bequem über je einen eigenen Editor eingegeben werden.
// Hierfür wird für jeden Tab ein Feld (Feld-Tytp WYSIWYG-Editor) mit Hilfe des WordPress-Plugins Plugins ACF (=Advanced Custom Fields) erstellt.
// CREATE TABS
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab "Programm"
$tabs['programm_tab'] = array(
'title' => __( 'PROGRAMM', 'woocommerce' ),
'priority' => 30,
'callback' => 'woo_new_product_tab_content1'
);
// Adds the new tab "Highlights"
$tabs['highlights_tab'] = array(
'title' => __( 'HIGHLIGHTS', 'woocommerce' ),
'priority' => 40,
'callback' => 'woo_new_product_tab_content2'
);
// Adds the new tab "Unterkunft"
$tabs['unterkunft_tab'] = array(
'title' => __( 'UNTERKUNFT', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content3'
);
// Adds the new tab "Leistungen, Termine & Preise"
$tabs['leistungen_tab'] = array(
'title' => __( 'LEISTUNGEN & PREISE', 'woocommerce' ),
'priority' => 60,
'callback' => 'woo_new_product_tab_content4'
);
return $tabs;
}
// CREATE CONTENTS (with ACF-Plugin)
function woo_new_product_tab_content1() {
// The new tab content for tab "Programm"
echo the_field('reiter-programm'); /* 'reiter-programm' durch eigenen ACF-Feldnamen ersetzen */
}
function woo_new_product_tab_content2() {
// The new tab content for tab "Highlights"
echo the_field('reiter-highlights'); /* 'reiter-highlights' durch eigenen ACF-Feldnamen ersetzen */
}
function woo_new_product_tab_content3() {
// The new tab content for tab "Unterkunft"
echo the_field('reiter-unterkunft'); /* 'reiter-unterkunft' durch eigenen ACF-Feldnamen ersetzen */
}
function woo_new_product_tab_content4() {
// The new tab content for tab "Leistungen, Termine & Preise"
echo the_field('reiter-leistungen'); /* 'reiter-leistungen' durch eigenen ACF-Feldnamen ersetzen */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment