WooCommerce 단일 제품 페이지에 여러 탭 추가
저는 wooCommerce에 3개의 커스텀 탭을 추가하려고 합니다.아래 코드가 있는데 그 중 2개가 뜨는데 어떤 이유로 속성 설명 탭이 페이지에 나타나지 않습니다.수량 가격 탭에 설명이 표시되지 않을 뿐만 아니라.코드의 여러 섹션을 다른 위치로 이동하려고 했고 코드에 오류가 있거나 누락된 섹션이 있는지 확인했습니다.이것은 내가 얻을 수 있는 최대한 가까운 것입니다.
제가 진행하는 과정은 기본적으로 제가 원하지 않는 기존 탭을 제거한 후에 제가 원하는 순서대로 새로운 탭을 추가하는 것입니다.
뭔가 부족한 느낌이 들어요.
여기서 사이트를 보실 수 있습니다: 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에서 회신당 편집, 이것이 나의 전체 기능입니다.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>';
}
?>
같은 후크를 4번 사용하시니woocommerce_product_tabs
, 당신의 문제는 첫번째 문제에서 가장 우선순위가 높습니다.대신 한 번만 사용하고, 네 개의 후크 기능을 하나로 병합해야 합니다.
약간 변경된 기능 테스트 코드는 다음과(와 같습니다.
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
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 and set the right order
//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>';
}
이 코드는 작동합니다.활성 하위 테마(또는 테마)의 php 파일 또는 플러그인 파일에 있습니다.
테스트를 거쳐 작동합니다.
동일한 후크에서 다음을 수행할 수 있습니다.
- 탭 제거
- 탭 추가
- 탭 재정렬
관련 공식 문서:제품 데이터 탭 편집
추가한 것은 추가하기 전에 탭에 콘텐츠가 존재하는지 확인하는 것뿐이었습니다.저는 단순히 'if' 문으로 새 배열을 감쌌습니다.
if (!empty(get_the_content())) {
$tabs['tab'] = array(
'title' => __( 'Tab Title', 'woocommerce' ),
'priority' => 100,
'callback' => 'woo_tab_content'
);
}
function my_simple_custom_product_tab( $tabs ) {
$tabs['my_custom_tab'] = array(
'title' => __( 'Custom Tab', 'textdomain' ),
'callback' => 'my_simple_custom_tab_content',
'priority' => 50,
);
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'my_simple_custom_product_tab' );
/**
* Function that displays output for the shipping tab.
*/
function my_simple_custom_tab_content( $slug, $tab ) {
?><h2><?php echo wp_kses_post( $tab['title'] ); ?></h2>
<p>Tab Content</p><?php
}
언급URL : https://stackoverflow.com/questions/39964939/adding-multiple-tabs-to-woocommerce-single-product-pages
'code' 카테고리의 다른 글
mysql WHERE 절에서 "IN"의 값을 동적으로 추가하는 방법은? (0) | 2023.09.15 |
---|---|
웹 응용프로그램용 파일 저장소:파일 시스템 대 DB 대 NoSQL 엔진 (0) | 2023.09.15 |
pyspark에서 데이터의 각 행을 루프하는 방법프레임 (0) | 2023.09.15 |
Android SDK Manager가 구성 요소를 설치하지 않음 (0) | 2023.09.15 |
NSUInter 대 NSInter, Int 대 Unsigned 및 유사한 경우 (0) | 2023.09.15 |