回声数组项

时间:2019-05-22 11:19:14

标签: php arrays echo

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

我有一个包含条款=>订阅的数组,需要将该字段拉入我的输入data-subscription =“ [这里的回显订阅]”

$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;

1 个答案:

答案 0 :(得分:1)

替换此行

<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]" />

使用

<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="<?php echo ($tax_query_args['tax_query'][0]['terms']); ?>" />