wpgenie

fix for bid input - XStore theme

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