Advertisement
wpgenie

fix for bid input - XStore theme

Dec 4th, 2023 (edited)
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.01 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Auction bid form template
  4.  *
  5.  * template should be copied to /xstore-child/woocommerce/single-product/auction-bid-form.php
  6.  *
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) {
  9.     exit; // Exit if accessed directly
  10. }
  11. global $product, $post;
  12. if ( ! ( $product && $product->get_type() == 'auction' ) ) {
  13.     return;
  14. }
  15. $current_user     = wp_get_current_user();
  16. $product_id       = $product->get_id();
  17. $user_max_bid     = $product->get_user_max_bid( $product_id, $current_user->ID );
  18. $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' );
  19. ?>
  20. <?php if ( ( $product->is_closed() === false ) and ( $product->is_started() === true ) ) : ?>  
  21.     <?php do_action( 'woocommerce_before_bid_form' ); ?>
  22.     <form class="auction_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo esc_attr( $product_id ); ?>">
  23.         <?php do_action( 'woocommerce_before_bid_button' ); ?>
  24.         <input type="hidden" name="bid" value="<?php echo esc_attr( $product_id ); ?>" />  
  25.        
  26.         <div class="quantity buttons_added">
  27.             <input type="button" value="+" class="plusauction" />
  28.             <input type="text" name="bid_value"
  29.                 data-auction-id="<?php echo esc_attr( $product_id ); ?>"
  30.             <?php if ( $product->get_auction_sealed() != 'yes' ) { ?>
  31.                 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() ) ); ?>"
  32.             <?php } ?>
  33.             <?php
  34.             if ($product->get_auction_sealed() != 'yes'){
  35.                 if ( $product->get_auction_type() == 'reverse' ) { ?>
  36.                     max="<?php echo esc_attr( number_format( $product->bid_value(), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator() ) ); ?>"
  37.                 <?php } else { ?>
  38.                     min="<?php echo esc_attr( number_format( $product->bid_value(), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator() ) ); ?>"
  39.                 <?php } ?>
  40.             <?php } ?>
  41.                 step="any"
  42.                 size="<?php echo strlen( $product->get_curent_bid() ) + 2; ?>"
  43.                 title="bid"
  44.                 class="input-text qty bid text left"
  45.             />
  46.             <input type="button" value="-" class="minusauction" />
  47.         </div>
  48.         <button type="submit" class="bid_button button alt"><?php echo apply_filters( 'bid_text', esc_html__( 'Bid', 'wc_simple_auctions' ), $product ); ?></button>
  49.        
  50.         <input type="hidden" name="place-bid" value="<?php echo esc_attr( $product_id ); ?>" />
  51.         <input type="hidden" name="product_id" value="<?php echo esc_attr( $product_id ); ?>" />
  52.         <?php if ( is_user_logged_in() ) { ?>
  53.             <input type="hidden" name="user_id" value="<?php echo get_current_user_id(); ?>" />
  54.         <?php } ?>
  55.         <?php do_action( 'woocommerce_after_bid_button' ); ?>
  56.     </form>
  57.     <script type="text/javascript">
  58.         jQuery(document).on("click", ".auction_form .plusauction,.auction_form .minusauction", function() {
  59.             console.log('click on action');
  60.             var t = jQuery(this).closest(".quantity").find("input[name=bid_value]"),
  61.                 a = parseFloat(jQuery(this).parents('.auction_form').find('.qty').autoNumeric('get')),
  62.                 n = parseFloat(t.attr("max")),
  63.                 s = parseFloat(t.attr("min")),
  64.                 vb = '',
  65.                 e = t.attr("step");
  66.                 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),
  67.                 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) ) ),
  68.                 t.trigger("change"),
  69.                 $('.auction_form .qty').autoNumeric('update');
  70.         });
  71.         function number_format (number , decimals = autoNumericdata.decimalPlacesOverride, dec_point = autoNumericdata.decimalCharacter, thousands_sep = autoNumericdata.digitGroupSeparator) {
  72.         // Strip all characters but numerical ones.
  73.         number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
  74.         var n = !isFinite(+number) ? 0 : +number,
  75.             prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
  76.             sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
  77.             dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
  78.             s = '',
  79.             toFixedFix = function (n, prec) {
  80.                 var k = Math.pow(10, prec);
  81.                 return '' + Math.round(n * k) / k;
  82.             };
  83.         // Fix for IE parseFloat(0.55).toFixed(0) = 0;
  84.         s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
  85.         if (s[0].length > 3) {
  86.             s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
  87.         }
  88.         if ((s[1] || '').length < prec) {
  89.             s[1] = s[1] || '';
  90.             s[1] += new Array(prec - s[1].length + 1).join('0');
  91.         }
  92.         return s.join(dec);
  93.     }
  94.     </script>
  95.     <?php do_action( 'woocommerce_after_bid_form' ); ?>    
  96. <?php endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement