如何在此片段中添加php条件

问题描述 投票:0回答:2

任何人都可以使用if条件修改以下代码以执行以下操作:

如果名为“uwa_auction_bids_history”的选项卡存在,那么选项卡的重新排序将按原样完成,但如果它不存在,则只需要重新排序的前两个选项卡(“description&additional_information”)它应该是基本的if /要添加到此片段的其他条件,但我没有PHP知识,所以我需要一个善良的人的帮助...

谢谢!

/**
 * Reorder product data tabs
 */
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {

    $tabs['description']['priority'] = 5;           // Reviews first
    $tabs['additional_information']['priority'] = 10;           // Description second
    $tabs['uwa_auction_bids_history']['priority'] = 15; // Additional information third

    return $tabs;
}
if-statement tabs code-snippets
2个回答
0
投票
/**
 * Reorder product data tabs
 */
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {

    $tabs['description']['priority'] = 5;           // Reviews first
    $tabs['additional_information']['priority'] = 10;           // Description second
    if ($tabs[''] !== undefined)
    {
        $tabs['uwa_auction_bids_history']['priority'] = 15; // Additional information third
    }
    return $tabs;
}

0
投票

基于Slobodan的帮助,我调整了代码以满足我的需求。感谢Slobodan的帮助!问题解决了!

/**
 * Reorder product data tabs
 */
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
    if ($tabs[''] !== undefined)
    $tabs['description']['priority'] = 5;           // Description first
    $tabs['additional_information']['priority'] = 10;           // Details second
    {
    $tabs['description']['priority'] = 5;           // Description first
    $tabs['additional_information']['priority'] = 10;           // Details second      $tabs['uwa_auction_bids_history']['priority'] = 15; // Bids third      
    }
    return $tabs;
}
© www.soinside.com 2019 - 2024. All rights reserved.