私は3つのカスタムタブをWooCommerceに追加しようとしています。以下のコードがあり、そのうち2つが表示されますが、何らかの理由で属性の説明タブがページに表示されません。数量料金設定タブにはその説明が表示されていないだけでなく、コードの異なるセクションを別々の場所に移動しようとしましたが、エラーまたは欠落したセクションのコードをチェックしました。これは私がそれを得ることができるほど近いです。WooCommerceの単一の製品ページに複数のタブを追加する
私のプロセスでは、基本的に私が望まない既存のタブを削除し、新しいタブを表示したい順に追加します。
私は何かが不足していると感じています。あなたがここにサイトを見ることができます
:http://demo.bergdahl.com/product/6-oz-catridge/
をここで私が使用していたコードです:返信あたり
// WooCommerce Tabs
// REMOVE EXISTING TABS
add_filter('woocommerce_product_tabs', 'woo_remove_product_tabs', 98);
function woo_remove_product_tabs($tabs) {
unset($tabs['description']); // Remove the description tab
// unset($tabs['reviews']); // Remove the reviews tab
unset($tabs['additional_information']); // Remove the additional information tab
return $tabs;
}
// ADD ATTRIBUTE DESCRIPTION TAB
add_filter('woocommerce_product_tabs', 'woo_attrib_desc_tab');
function woo_attrib_desc_tab($tabs) {
// Adds the Attribute Description tab
$tabs['attrib_desc_tab'] = array(
'title' => __('Desc', 'woocommerce'),
'priority' => 100,
'callback' => 'woo_attrib_desc_tab_content'
);
return $tabs;
}
// ADD QUANTITY PRICING TAB
add_filter('woocommerce_product_tabs', 'woo_qty_pricing_tab');
function woo_qty_pricing_tab($tabs) {
// Adds the qty pricing tab
$tabs['qty_pricing_tab'] = array(
'title' => __('Quantity Pricing', 'woocommerce'),
'priority' => 110,
'callback' => 'woo_qty_pricing_tab_content'
);
return $tabs;
}
// ADD OTHER PRODUCTS TAB
add_filter('woocommerce_product_tabs', 'woo_other_products_tab');
function woo_other_products_tab($tabs) {
// Adds the other products tab
$tabs['other_products_tab'] = array(
'title' => __('Other Products', 'woocommerce'),
'priority' => 120,
'callback' => 'woo_other_products_tab_content'
);
return $tabs;
}
// ADD CUSTOM TAB DESCRIPTIONS
function woo_attrib_desc_tab_content() {
// The attribute description tab content
echo '<h2>Description</h2>';
echo '<p>Custom description tab.</p>';
}
function woo_qty_pricing_tab_content() {
// The qty pricing tab content
echo '<h2>Quantity Pricing</h2>';
echo '<p>Here\'s your quantity pricing tab.</p>';
}
function woo_other_products_tab_content() {
// The other products tab content
echo '<h2>Other Products</h2>';
echo '<p>Here\'s your other products tab.</p>';
}
編集を以下LoicTheAztecからは、これは私の全体のfunctions.phpファイルです。私は底に?>
ととせずに、それを試してみました:
<?php
add_theme_support('builder-3.0');
add_theme_support('builder-responsive');
function register_my_fonts() {
wp_register_style('googleFonts-OpenSans', '//fonts.googleapis.com/css?family=Open+Sans:400,300,700');
wp_enqueue_style('googleFonts-OpenSans');
}
add_action('wp_enqueue_scripts', 'register_my_fonts');
function sc_replacecolon($content){ return str_replace('[sc:', '[sc name=', $content); }
add_filter('the_content', 'sc_replacecolon', 5);
/* WOOCOMMERCE */
add_filter('woocommerce_product_tabs', 'woo_custom_product_tabs', 100, 1);
function woo_custom_product_tabs($tabs) {
// 1) Removing tabs
unset($tabs['description']); // Remove the description tab
// unset($tabs['reviews']); // Remove the reviews tab
unset($tabs['additional_information']); // Remove the additional information tab
// 2 Adding new tabs
//Attribute Description tab
$tabs['attrib_desc_tab'] = array(
'title' => __('Desc', 'woocommerce'),
'priority' => 100,
'callback' => 'woo_attrib_desc_tab_content'
);
// Adds the qty pricing tab
$tabs['qty_pricing_tab'] = array(
'title' => __('Quantity Pricing', 'woocommerce'),
'priority' => 110,
'callback' => 'woo_qty_pricing_tab_content'
);
// Adds the other products tab
$tabs['other_products_tab'] = array(
'title' => __('Other Products', 'woocommerce'),
'priority' => 120,
'callback' => 'woo_other_products_tab_content'
);
return $tabs;
}
// New Tab contents
function woo_attrib_desc_tab_content() {
// The attribute description tab content
echo '<h2>Description</h2>';
echo '<p>Custom description tab.</p>';
}
function woo_qty_pricing_tab_content() {
// The qty pricing tab content
echo '<h2>Quantity Pricing</h2>';
echo '<p>Here\'s your quantity pricing tab.</p>';
}
function woo_other_products_tab_content() {
// The other products tab content
echo '<h2>Other Products</h2>';
echo '<p>Here\'s your other products tab.</p>';
}
?>
「サイトが壊れました」というのは構文エラーの95%です。 ['WP_DEBUG'](https://codex.wordpress.org/Debugging_in_WordPress)を有効にすると、より有用なエラーの説明を得ることができます。 – helgatheviking
私のfunctions.phpの上にLoicのコードを追加して取得する:Parse error:構文エラー、/ home/parkyay/public_html/demo/wp-content/themes/BuilderChild-Default /にある予期しない 'add_filter'(T_STRING) functions.php on line 1 – MattM
エラーはそれが1行目だと言います。私が推測しなければならないのは、親テーマの 'functions.php'に問題があることを示しています。私は上記の 'functions.php'をTwenty Sixteenの子テーマとして使用しましたが、エラーは発生しません。 – helgatheviking