第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自定義 Woocommerce 產(chǎn)品列表短代碼

自定義 Woocommerce 產(chǎn)品列表短代碼

PHP
開滿天機 2022-07-09 16:08:47
我正在嘗試創(chuàng)建一個簡單的自定義 Woocommerce 產(chǎn)品短代碼,它將獲得如下產(chǎn)品列表:[custom_products_list ids='32,21,44,56']并將輸出帶有 URL、標(biāo)題、按名稱排序和 ACS 的產(chǎn)品不需要其他信息,不需要縮略圖或其他。就如上。我不想故意使用默認(rèn)產(chǎn)品簡碼。我將不勝感激任何幫助!提前致謝!
查看完整描述

1 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗 獲得超17個贊

像這樣的東西...


function custom_product_list_shortcode( $atts, $content = null ) {


    $_atts =  shortcode_atts( [

        'ids' => '',

    ], $atts );


    $ids_arr = array_filter( array_map( function( $id ){

        return trim( $id );

    }, explode( ',', $_atts['ids'] ) ) );


    $products = wc_get_products( [

        'post_status' => 'publish',

        // can't remember if it's 'orderby' or 'order_by'

        'order_by' => [

            'title' => 'ASC',

            'post_date' => 'DESC',

        ],

        'posts_per_page' => -1,

        // you can probably just pass in the comma sep string instead of array but maybe not.

        // you need to check that post__in is correct. look at the docs for WP_Query, or WC_Query, or wc_get_products()

        'post__in' => $ids_arr,

    ]);


    // you could write your own sorting function like this if you want but you probably shouldn't need to

    // rsort( $products, function( $p1, $p2 ) {});


    // the html is for you to complete

    ob_start();

    ?>

    <div class="products-list">

        <?php foreach ( $products as $product ) { ?>

            <div class="product">

                <pre>

                    <?= print_r( $product, true ); ?>

                    <?= get_title( $product->ID ); ?>

                </pre>

            </div>

        <?php } ?>

    </div>

    <?php

    return ob_get_clean();

}


add_shortcode( 'custom_product_list', 'custom_product_list_shortcode' );


查看完整回答
反對 回復(fù) 2022-07-09
  • 1 回答
  • 0 關(guān)注
  • 151 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號