Created
July 28, 2017 08:40
-
-
Save nczz/5c2483b491879b0c9acf66f291fd2a10 to your computer and use it in GitHub Desktop.
WooCommerce 建立商品下拉選單
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array('post_type' => 'product', 'posts_per_page' => -1, 'product_cat' => '分類名稱', 'orderby' => 'ASC'); | |
$loop = new WP_Query($args); | |
$dropdownlist = '<select id="cate_name">'; | |
while ($loop->have_posts()) { | |
$loop->the_post(); | |
$_product = wc_get_product($loop->post->ID); | |
$dropdownlist .= '<option value="' . $loop->post->ID . '" data-price="' . $_product->get_price() . '">' . $loop->post->post_title . '</option>'; | |
} | |
$dropdownlist .= '</select>'; | |
wp_reset_query(); | |
echo '分類名稱:' . $dropdownlist; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment