gpt4 book ai didi

php - 无法在单个产品页面中重新排序产品标签?

转载 作者:行者123 更新时间:2023-12-05 06:27:38 24 4
gpt4 key购买 nike

我正在尝试将单个产品页面中的产品选项卡从描述、评论重新排序为评论、描述。我遇到了 woocommerce 文档,它解释了如何做并尝试了示例代码。但是当我在我的 functions.php 文件中添加代码时没有任何反应。我做错了什么?这是我的示例代码

<?php
/**
* Kidz-Child functions and definitions
*
* @package kidz-child
*/

/** Loading language **/
add_action( 'after_setup_theme', 'kidz_child_theme_setup' );
function kidz_child_theme_setup() {
load_child_theme_textdomain( 'kidz', get_stylesheet_directory() . '/languages' );
load_textdomain( 'ideapark-wishlist', get_stylesheet_directory() . '/languages/' . 'ideapark-wishlist' . '-' . apply_filters( 'plugin_locale', get_locale(), 'ideapark-wishlist' ) . '.mo' );
load_textdomain( 'ideapark-theme-functionality', get_stylesheet_directory() . '/languages/' . 'ideapark-theme-functionality' . '-' . apply_filters( 'plugin_locale', get_locale(), 'ideapark-theme-functionality' ) . '.mo' );
}

/** Enqueue the child theme stylesheet **/
add_action( 'wp_enqueue_scripts', 'kidz_child_enqueue_scripts', 100 );
function kidz_child_enqueue_scripts() {
wp_enqueue_style( 'kidz-child-style', get_stylesheet_directory_uri() . '/style.css' );
}

function wc_billing_field_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing Details' :
$translated_text = __( 'Your Details', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );

add_action( 'woocommerce_before_cart_table', 'woo_add_continue_shopping_button_to_cart' );
function woo_add_continue_shopping_button_to_cart() {
$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );

echo '<div class="woocommerce-message">';
echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping →</a> Would you like some more goods?';
echo '</div>';
}



remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );

add_action('init', 'add_new_star_rating');
function add_new_star_rating()
{
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 6 );
}

function wc_direct_link_to_product_tabs() {
if( is_product() ) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {

if( window.location.hash ) {

// Vars
var tab = window.location.hash.replace('#', '');
var tab_content = 'tab-' + tab;

// Tabs
$( 'li.description_tab' ).removeClass( 'active' );
$( 'li.' + tab + '_tab' ).addClass( 'active' );

// Tabs content
$( '#tab-description' ).hide();
$( '#' + tab_content ).show();
}

// when the tab is selected update the url with the hash
$(".tabs a").click( function() {
window.location.hash = $(this).parent('li').attr("class").replace(' active', '').replace('_tab', '');
});

});
</script>

<?php
}
}


add_action( 'wp_footer', 'wc_direct_link_to_product_tabs', 30 );
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {

$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second


return $tabs;
}

最佳答案

您可以在主题的 functions.php 或自定义模块中使用此代码片段 文件。

add_filter( 'woocommerce_product_tabs', function ( $tabs ) {
$tab_list = [
'description' => 10,
'additional_information' => 15,
'reviews' => 5,
];
foreach ( $tab_list as $tab => $priority ) {
if ( isset( $tabs[ $tab ] ) ) {
$tabs[ $tab ]['priority'] = $priority;
}
}
return $tabs;
}, 98 );

关于php - 无法在单个产品页面中重新排序产品标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55115230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com