回波数组项

我正在寻找回显数组的一部分,将数组的一部分回显到数据字段中的最佳方法是什么


我有一个包含条款 => 订阅的数组,需要将该字段拉入我的输入 data-subscription="[echo subscription in here ]"


$quantites_required = false;

$previous_post      = $post;

$count              = 0;

$tax_query_args     = [

    'post_type' => 'product',

    'tax_query' => [

        [

            'taxonomy' => 'product_type',

            'field'    => 'name',

            'terms'    => 'subscription',

        ],

    ],

];

$tax_query = get_posts($tax_query_args);

global $grouped_product;

foreach ($tax_query as $post) {

    global $post;

    $price = get_post_meta(get_the_ID(), '_price', true);

    ?>

<li id="product-<?php the_ID();?>" <?php post_class();?>>

    <div class="prod-name">

        <div class="radio">

            <input type="checkbox" id="product-<?php the_ID();?>" value="1" name="quantity[<?php the_ID();?>]" class="wc-grouped-product-add-to-cart-checkbox js-group-item-sel" <?php echo ($count != 0 ? '' : ' checked="checked"'); ?> data-subscription="[echo terms subrciptions here]" />

            <label for="product-<?php the_ID();?>">

                <?php echo the_title(); ?>

            </label>

        </div>

    </div>

    <div class="prod-price" data-price="<?php echo number_format($price, 2); ?>">

        <p>

            <?php echo wc_price($price); ?>

        </p>

    </div>

    <div class="prod_flag">

        <?php get_product_flags(true); //Hide featured for grouped child items. ?>

    </div>

    <?php

$count = $count + 1;

}

$count = 0;


繁星coding
浏览 129回答 1
1回答

侃侃尔雅

替换这一行<input&nbsp;type="checkbox"&nbsp;id="product-<?php&nbsp;the_ID();?>"&nbsp;value="1"&nbsp;name="quantity[<?php&nbsp;the_ID();?>]"&nbsp;class="wc-grouped-product-add-to-cart-checkbox&nbsp;js-group-item-sel"&nbsp;<?php&nbsp;echo&nbsp;($count&nbsp;!=&nbsp;0&nbsp;?&nbsp;''&nbsp;:&nbsp;'&nbsp;checked="checked"');&nbsp;?>&nbsp;data-subscription="[echo&nbsp;terms&nbsp;subrciptions&nbsp;here]"&nbsp;/>和<input&nbsp;type="checkbox"&nbsp;id="product-<?php&nbsp;the_ID();?>"&nbsp;value="1"&nbsp;name="quantity[<?php&nbsp;the_ID();?>]"&nbsp;class="wc-grouped-product-add-to-cart-checkbox&nbsp;js-group-item-sel"&nbsp;<?php&nbsp;echo&nbsp;($count&nbsp;!=&nbsp;0&nbsp;?&nbsp;''&nbsp;:&nbsp;'&nbsp;checked="checked"');&nbsp;?>&nbsp;data-subscription="<?php&nbsp;echo&nbsp;($tax_query_args['tax_query'][0]['terms']);&nbsp;?>"&nbsp;/>
打开App,查看更多内容
随时随地看视频慕课网APP