gpt4 book ai didi

php - WooCommerce 抽奖号码 : Add leading zeros to lottery numbers

转载 作者:行者123 更新时间:2023-12-04 08:32:50 27 4
gpt4 key购买 nike

关闭。这个问题需要debugging details .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

9 个月前关闭。




Improve this question



  • 我想编辑我的付费 WooCommerce 插件。它生成 1、2、3、4 中的彩票号码,我想要 4 位数字,如 0001、0002、0003、0004。
     function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {
    if ( is_null( $product ) ) {
    $product = $GLOBALS['product'];
    }

    $defaults = array(
    'input_id' => uniqid( 'quantity_' ),
    'input_name' => 'quantity',
    'input_value' => '1',
    'classes' => apply_filters( 'woocommerce_quantity_input_classes', array( 'input-text', 'qty', 'text' ), $product ),
    'max_value' => apply_filters( 'woocommerce_quantity_input_max', -1, $product ),
    'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $product ),
    'step' => apply_filters( 'woocommerce_quantity_input_step', 1, $product ),
    'pattern' => apply_filters( 'woocommerce_quantity_input_pattern', has_filter( 'woocommerce_stock_amount', 'intval' ) ? '[0-9]*' : '' ),
    'inputmode' => apply_filters( 'woocommerce_quantity_input_inputmode', has_filter( 'woocommerce_stock_amount', 'intval' ) ? 'numeric' : '' ),
    );

    $args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, $defaults ), $product );

    // Apply sanity to min/max args - min cannot be lower than 0.
    $args['min_value'] = max( $args['min_value'], 0 );
    $args['max_value'] = 0 < $args['max_value'] ? $args['max_value'] : '';

    // Max cannot be lower than min if defined.
    if ( '' !== $args['max_value'] && $args['max_value'] < $args['min_value'] ) {
    $args['max_value'] = $args['min_value'];
    }

    ob_start();

    if ( get_post_meta( $product->get_id() , '_lottery_use_pick_numbers', true ) === 'yes' && "yes" !== get_post_meta( $product->get_id() , '_lottery_pick_numbers_random', true ) && $args['input_id'] != 'qty_dip') {
    echo '<div class="quantity">
    <input type="hidden" id="' .esc_attr( $args['input_id'] ) . '" class="qty" name="' . esc_attr( $args['input_name'] ) . '" value="' . esc_attr($args['input_value']) . '" />
    '.$args['input_value'].'
    </div>';
    } else {
    wc_get_template( 'global/quantity-input.php', $args );
    }


    if ( $echo ) {
    echo ob_get_clean(); // WPCS: XSS ok.
    } else {
    return ob_get_clean();
    }
    }
  • 最佳答案

    您的问题太抽象了,但是您可以使用 WordPress 内置的格式化功能来实现您想要的输出 zeroise() .
    WordPress zeroise() function 的官方文档
    WordPress(5.5.3 版)源代码 zeroise() function

    关于php - WooCommerce 抽奖号码 : Add leading zeros to lottery numbers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64939750/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com