无法在单产品页面中重新订购产品选项卡



我正在尝试将单个产品页面中的"产品"选项卡从描述,评论到评论,描述。我遇到了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 );

这对我在function.php -Child主题中有用:

/*** Reorder product data tabs*/
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
$tabs['additional_information']['priority'] = 5; // Additional information first    
$tabs['description']['priority'] = 10; // Description second
return $tabs;
}

相关内容

最新更新