Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Auction bid form template
- *
- * template should be copied to /xstore-child/woocommerce/single-product/auction-bid-form.php
- *
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly
- }
-
- global $product, $post;
-
- if ( ! ( $product && $product->get_type() == 'auction' ) ) {
- return;
- }
- $current_user = wp_get_current_user();
- $product_id = $product->get_id();
- $user_max_bid = $product->get_user_max_bid( $product_id, $current_user->ID );
- $max_min_bid_text = $product->get_auction_type() == 'reverse' ? esc_html__( 'Your min bid is', 'wc_simple_auctions' ) : esc_html__( 'Your max bid is', 'wc_simple_auctions' );
- ?>
-
- <?php if ( ( $product->is_closed() === false ) and ( $product->is_started() === true ) ) : ?>
-
- <?php do_action( 'woocommerce_before_bid_form' ); ?>
-
- <form class="auction_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo esc_attr( $product_id ); ?>">
-
- <?php do_action( 'woocommerce_before_bid_button' ); ?>
-
- <input type="hidden" name="bid" value="<?php echo esc_attr( $product_id ); ?>" />
- <div class="quantity buttons_added">
-
- <input type="button" value="+" class="plusauction" />
-
- <input type="text" name="bid_value"
- data-auction-id="<?php echo esc_attr( $product_id ); ?>"
- <?php if ( $product->get_auction_sealed() != 'yes' ) { ?>
- value="<?php echo esc_attr( number_format( $product->bid_value(), wc_get_price_decimals() == 0 ? 2 : wc_get_price_decimals() , wc_get_price_decimal_separator(), wc_get_price_thousand_separator() ) ); ?>"
- <?php } ?>
-
- <?php
- if ($product->get_auction_sealed() != 'yes'){
- if ( $product->get_auction_type() == 'reverse' ) { ?>
- max="<?php echo esc_attr( number_format( $product->bid_value(), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator() ) ); ?>"
- <?php } else { ?>
- min="<?php echo esc_attr( number_format( $product->bid_value(), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator() ) ); ?>"
- <?php } ?>
- <?php } ?>
- step="any"
- size="<?php echo strlen( $product->get_curent_bid() ) + 2; ?>"
- title="bid"
- class="input-text qty bid text left"
- />
- <input type="button" value="-" class="minusauction" />
- </div>
-
- <button type="submit" class="bid_button button alt"><?php echo apply_filters( 'bid_text', esc_html__( 'Bid', 'wc_simple_auctions' ), $product ); ?></button>
- <input type="hidden" name="place-bid" value="<?php echo esc_attr( $product_id ); ?>" />
- <input type="hidden" name="product_id" value="<?php echo esc_attr( $product_id ); ?>" />
-
- <?php if ( is_user_logged_in() ) { ?>
- <input type="hidden" name="user_id" value="<?php echo get_current_user_id(); ?>" />
- <?php } ?>
-
- <?php do_action( 'woocommerce_after_bid_button' ); ?>
-
- </form>
- <script type="text/javascript">
- jQuery(document).on("click", ".auction_form .plusauction,.auction_form .minusauction", function() {
- console.log('click on action');
- var t = jQuery(this).closest(".quantity").find("input[name=bid_value]"),
- a = parseFloat(jQuery(this).parents('.auction_form').find('.qty').autoNumeric('get')),
- n = parseFloat(t.attr("max")),
- s = parseFloat(t.attr("min")),
- vb = '',
- e = t.attr("step");
- a && "" !== a && "NaN" !== a || (a = 0), ("" === n || "NaN" === n) && (n = ""), ("" === s || "NaN" === s) && (s = 0), ("any" === e || "" === e || void 0 === e || "NaN" === parseFloat(e)) && (e = 1),
- jQuery(this).is(".plusauction") ? t.val(number_format(n && (n == a || a > n) ? n : a + parseFloat(e) )) : s && (s == a || s > a) ? t.val(number_format( s ) ) : a > 0 && t.val( number_format (a - parseFloat(e) ) ),
- t.trigger("change"),
- $('.auction_form .qty').autoNumeric('update');
-
- });
- function number_format (number , decimals = autoNumericdata.decimalPlacesOverride, dec_point = autoNumericdata.decimalCharacter, thousands_sep = autoNumericdata.digitGroupSeparator) {
- // Strip all characters but numerical ones.
- number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
- var n = !isFinite(+number) ? 0 : +number,
- prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
- sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
- dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
- s = '',
- toFixedFix = function (n, prec) {
- var k = Math.pow(10, prec);
- return '' + Math.round(n * k) / k;
- };
- // Fix for IE parseFloat(0.55).toFixed(0) = 0;
- s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
- if (s[0].length > 3) {
- s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
- }
- if ((s[1] || '').length < prec) {
- s[1] = s[1] || '';
- s[1] += new Array(prec - s[1].length + 1).join('0');
- }
- return s.join(dec);
- }
- </script>
- <?php do_action( 'woocommerce_after_bid_form' ); ?>
-
- <?php endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement