1

I have woocommerce auction product template created in WordPress using Oxygen Builder. I need recount price, when currency is changeed to €, or to $ and I click on bid button. After that, javascript below starts, but it does not recalculate the price.

I am using Ultimate WooCommerce Auction Pro - Business plugin for auctions and Currency Switcher for WooCommerce for switching currency.

<script type="text/javascript">
var curentpageenddate='<?php  echo strtotime( $uwa_ending_time );?>';
console.log(curentpageenddate);
jQuery("document").ready(function($){

    $("#placebidbutton_direct").on('click', function(event){

        var formname = "directbid";         
        retval = bid_check(formname);
        
        if(retval == true || retval == false){              
            return retval;
        }
    });
    
    $("#placebidbutton").on('click', function(event){
        
        var formname = "custombid";
        retval = bid_check(formname);
        
        if(retval == true || retval == false){              
            return retval;
        }
    });

    function bid_check(formname){           

        var id_Bid;

        if(formname == "custombid"){
            id_Bid = "#uwa_bid_value";
        }
        else if(formname == "directbid"){
            id_Bid = "#uwa_bid_value_direct";
        }

            var bidval = parseFloat($(id_Bid).val());

            if(bidval){             

                if(formname == "custombid"){
                        
                        var minval = parseFloat($(id_Bid).attr("min")); 
                        var maxval = parseFloat($(id_Bid).attr("max"));

                        if(minval <= bidval){
                            bid_process(formname, id_Bid);
                        }
                        else{                   
                            alert("<?php _e('Please enter bid value greater than suggested bid', 'woo_ua');?>");
                            return false;
                        }
                }
                else if(formname == "directbid"){
                    bid_process(formname, id_Bid);                      
                }

            } /* end of if - bidval */                                              
            else{
                alert("<?php _e('Please enter bid value', 'woo_ua');?>");
                return false;
            }

    } /* end of function */


    function bid_process(formname, id_Bid){
            
            <?php 

            $uwa_enable_bid_place_warning = 
                get_option('uwa_enable_bid_place_warning');
            $uwa_placebid_ajax_enable = 
                get_option('woo_ua_auctions_placebid_ajax_enable');

            if($uwa_placebid_ajax_enable == "no" || 
                $uwa_placebid_ajax_enable == ""){ /* using page load */
                if($uwa_enable_bid_place_warning  == "yes"){ ?>

                    confirm_bid(formname, id_Bid);

                <?php
                }       
            }elseif($uwa_placebid_ajax_enable == "yes"){ /* using ajax */
                if($uwa_enable_bid_place_warning  == "yes"){ ?>

                    var retval = confirm_bid(formname, id_Bid);
                    if(retval == true){ 

                        /* bid using ajax if confirm yes */
                        placebid_ajax_process(formname);
                    }
                <?php
                }
                else{?>
                    /* bid using ajax */
                    placebid_ajax_process(formname);
                <?php
                }
            }
            ?>

    } /* end of function */


    function placebid_ajax_process(formname){

        if(formname == "custombid"){
            id_Bid = "#uwa_bid_value";
            id_h_Product = "#uwa_place_bid";
            id_Bid_Button = "#placebidbutton";
            class_ajax_Span = ".ajax-loader-placebid";
            class_ajax_Img  = ".loaderimg";
        }
        else if(formname == "directbid"){
            id_Bid = "#uwa_bid_value_direct";
            id_h_Product = "#uwa_place_bid_direct";
            id_Bid_Button = "#placebidbutton_direct";
            class_ajax_Span = ".ajax-loader-placebid_direct";
            class_ajax_Img  = ".loaderimg_direct";
        }

        var uwa_place_bid = $(id_h_Product).val();
        var uwa_bid_value = $(id_Bid).val();
        var uwa_url = "<?php echo admin_url('admin-ajax.php'); ?>";     
        
        $.ajax({
            method : "post",  /* don't use 'type' */
            url : "<?php echo admin_url('admin-ajax.php'); ?>",             
            data :  {action: "uwa_ajax_placed_bid",
                    uwa_place_bid : uwa_place_bid,
                    uwa_bid_value : uwa_bid_value
                    },
            beforeSend: function(){ 
                $(class_ajax_Span).css("display", "inline");
                $(class_ajax_Img).css("visibility", "visible");
                $('.product-type-auction').css("opacity", "0.7");
                $("#placebidbutton").attr("disabled", "disabled");
                $("#placebidbutton_direct").attr("disabled", "disabled");
                $('.single_add_to_cart_button').attr("disabled", 
                    "disabled");
            },
            
            success: function(response) {
                
                var data = $.parseJSON( response );
                
                if(typeof data.allmsg != "undefined"){
                    //$(".woocommerce-notices-wrapper").hide();
                    //$(".woocommerce-notices-wrapper").html(data.allmsg).fadeIn(1000);
                    
                    $(".woocommerce-notices-wrapper").html(data.allmsg);
                }

                /* display fields data in detail page */
                //if(data.allstatus == 1){

                    var auctionid = uwa_place_bid;
                    var newprice = data.alldata_display.uwa_curent_bid;
                    var newenterval = data.alldata_display.entervalue;
                    var newwinusername = data.alldata_display.winusername;
                    var newreservetext = data.alldata_display.reservetext;
                    var newmaxmintext = data.alldata_display.maxmintext;
                    var newuwabidsalldata = data.alldata_display.uwa_bids_alldata;
                    var newbidminval = data.alldata_display.uwa_bid_minval;
                    var newbidmaxval = data.alldata_display.uwa_bid_maxval;
                    var newtimerval = data.alldata_display.remaining_secs;
                    var auctiontype = data.alldata_display.auction_type;

                    var newnextbids = data.alldata_display.next_bids;

                    var newuwa_imgtext = data.alldata_display.uwa_imgtext;
                    var newuwa_detailtext = data.alldata_display.uwa_detailtext;
                    var newuwa_buynow = data.alldata_display.uwa_buynow;

                    if(typeof newprice != "undefined"){
                        $("p.price").html(newprice); /* + "--done"); */
                    }
                    
                    if(typeof newenterval != 'undefined'){
                        newenterval = newenterval + " )";
                        /* uwa_inc_latest_price or uwa_inc_price_ajax_492 */
                        $("small.uwa_inc_latest_price").html(newenterval);
                    }

                    if(typeof newreservetext != 'undefined'){
                        //strong.uwa_auction_reserve_price                          
                        $("div.checkreserve").html(newreservetext);
                    }

                    if(typeof newwinusername != 'undefined'){

                        $("div.winner-name").html(newwinusername);
                    }

                    if(typeof newmaxmintext != 'undefined'){
                        $("p.max-bid").html(newmaxmintext);
                    }

                    if(typeof newtimerval != 'undefined'){
                        
                        //alert("inif --" + newtimerval);
                        /* change value of data-time of timer */
                        /*$("div.uwa_auction_product_countdown").data('time', newtimerval);*/
                        /* set new time value in div */
                        $("div.uwa_auction_product_countdown").attr(
                            'data-time', newtimerval);

                        time1 = newtimerval;
                        //alert(time1);
                        //alert(typeof time1);

                        /*$("div.uwa_auction_product_countdown").WooUacountdown('destroy');*/

                        /* here we add new time for timer, check uwa-front.js for all options of timer */

                        /*$("div.uwa_auction_product_countdown").WooUacountdown({until:   $.WooUacountdown.UTCDate(-(new Date().getTimezoneOffset()), new Date(time1*1000))});*/
                        
                    }

                    if(typeof newuwabidsalldata != 'undefined'){
                            /* uwa-front.js */
                        /*jQuery("#auction-history-table-" + key +" tbody > tr:first" ).before(value.wua_activity);*/

                        /*($(".auction-history-table  tbody > tr:first").before(newuwabidsalldata + "--done");*/

                        $("div.uwa_bids_history_data").html(newuwabidsalldata); /* + "--done");*/
                    }

                    if(typeof newbidminval != 'undefined'){

                        /* note : change min value for both direct and custom bid  **** */

                        $("#uwa_bid_value").attr("min", newbidminval);
                        /*$("#uwa_bid_value_direct").attr("min", 
                            newbidminval);*/


                        /* set default value for direct bid */
                        if(auctiontype == "normal"){
                            //$("#uwa_bid_value_direct").val(newbidminval);
                            //$("#uwa_bid_value_direct").html("<option value='1'>1</option><option value='2'>2</option>");
                            //$("#uwa_bid_value_direct").html(newnextbids);
                        }
                    }

                    if(typeof newnextbids != 'undefined'){

                        if(auctiontype == "normal"){

                            /* set options for direct bid */
                            $("#uwa_bid_value_direct").html(newnextbids);

                        }
                        
                    }

                    if(typeof newbidmaxval != 'undefined'){

                        /* note : change max value for both direct and custom bid  **** */

                        $("#uwa_bid_value").attr("max", newbidmaxval);
                        $("#uwa_bid_value_direct").attr("max", 
                            newbidmaxval);
                            
                        /* set default value for direct bid */
                        if(auctiontype == "reverse"){
                            $("#uwa_bid_value_direct").val(newbidmaxval);
                        }

                    }
                    
                    if(typeof newuwa_imgtext != "undefined"){
                        $("span.uwa_imgtext").html(newuwa_imgtext); 
                    }
                    else{                           
                        $("span.uwa_imgtext").html("");
                    }

                    if(typeof newuwa_detailtext != "undefined"){                            
                        $("p.uwa_detailtext").html(newuwa_detailtext);
                    }
                    else{                           
                        $("p.uwa_detailtext").html(""); 
                    }

                    if(typeof newuwa_buynow != "undefined"){
                        
                        if(newuwa_buynow != "yes"){
                            
                            $("form.buy-now .single_add_to_cart_button").css("display", 
                                "none");                                
                        }
                        else{
                            
                            $("form.buy-now .single_add_to_cart_button").css("display", 
                                "inline-block"); 
                        }                           
                    }

                    $("#uwa_bid_value").val("");
                    

                //}
                
            },
            error: function(){},

            complete: function(){
                $(class_ajax_Span).css("display", "none");
                $(class_ajax_Img).css("visibility", "hidden");
                $('.product-type-auction').css("opacity", "1"); 
                $("#placebidbutton").removeAttr("disabled");
                $("#placebidbutton_direct").removeAttr("disabled");
                $('.single_add_to_cart_button').removeAttr("disabled");
                

                /* -------- slider ---------- */

                var custom_add = 100;

                <?php  if(get_template() == "Divi"){ ?>                     

                    custom_add = 500;

                <?php } ?>


                    $("html").animate({scrollTop: ($(".woocommerce-notices-wrapper").offset().top)-custom_add}, 1500);
                    
                    $(".woocommerce-notices-wrapper").hide(); 
                    setTimeout(function(){
                       $(".woocommerce-notices-wrapper").fadeIn(2000);
                    }, 1000); 

                /* -------- slider ---------- */                    


            },
        });

    } /* end of function */


        /* Extra confirmation message on place bid */
    function  confirm_bid(formname, id_Bid) {

        /* Get bid value, format value and then add to confirm message */
        var bidval = jQuery(id_Bid).val();
        var bidval = parseFloat(bidval);

        if (bidval > 0){
            
            var floatbidval = bidval.toFixed(2); /* 2 numbers after decimal point */
            /*var currencyval = "<?php echo html_entity_decode(get_woocommerce_currency_symbol()); ?>";*/

            /* bloginfo( 'charset' ); */

            var currencyval = "<?php echo html_entity_decode(get_woocommerce_currency_symbol($product_base_currency), ENT_COMPAT | ENT_HTML401, 
                'UTF-8'); ?>";

            var finalval = currencyval + floatbidval;


            if(formname == "custombid"){
                var confirm1 = '<?php echo addslashes(__( "Do you really want to bid", "woo_ua" )); ?>';
            }
            else if(formname == "directbid"){
                var confirm1 = '<?php echo addslashes(__( "Do you really want to directly place this bid", "woo_ua" )); ?>';
            }

            
            var confirm_message = confirm1 + ' ' + finalval + ' ?';

            var result_conf = confirm(confirm_message);

            if(result_conf == false){
                event.preventDefault(); /* don't use return it reloads page */
            }
            else{
                return true;
            }
        }
        
    } /* end of function - confirm_bid() */


}); /* end of document ready */

0 Answers0