ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingเอาโค้ดแจ้งเตือน php ไปใส่ใน ajax ยังไงคะ woocommerce
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: เอาโค้ดแจ้งเตือน php ไปใส่ใน ajax ยังไงคะ woocommerce  (อ่าน 1247 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
bwnm29
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 18



ดูรายละเอียด
« เมื่อ: 02 กุมภาพันธ์ 2020, 12:45:23 »

สวัสดีค่ะ  เราเขียนโค้ด ajax ไว้โดยที่เวลากดปุ่มในหน้าสินค้า หน้าจะไม่รีเฟรส แล้วให้ส่งค่ากลับมาที่หน้าสินค้าเดิม
แต่ว่ามีสินค้าบางรายการที่ตั้งเป็นแบบพิเศษเอาไว้ ทีนี้ข้อความแจ้งเตือนสำหรับสินค้าตัวนั้นจะไม่แสดงเพราะไม่ได้กำหนดค่าใน ajax ไว้ เราจะใส่ค่าเพิ่มไปยังไงคะ ลองใส่แล้วมันไม่ขึ้น

อันนี้โค้ดใน php ถ้าเวลามันรีเฟรสปกติจะขึ้นความนี้มา

โค๊ด:
function woocommerce__simple_auctions_place_bid_message( $product_id ) {
global $woocommerce;
$product_data = wc_get_product($product_id);
$current_user = wp_get_current_user();

if($current_user->ID == $product_data->get_auction_current_bider()){
if(!$product_data->is_reserve_met() && ('yes' !== $product_data->get_auction_sealed() ) ){
$message = '<div class="reserve_not_meet" data-auction-id="' . $product_data -> get_id() . '" >' . sprintf( __( 'Successfully placed bid for &quot;%s&quot; but it does not meet the reserve price!', 'wc_simple_auctions' ),$product_data -> get_title()  ) .'</div>' ;
} else{

if($product_data->get_auction_proxy() && $product_data->get_auction_max_bid()){
$message = sprintf( __( 'Successfully placed bid for &quot;%s&quot;! Your max bid is %s.', 'wc_simple_auctions' ),$product_data -> get_title(), wc_price($product_data->get_auction_max_bid())  );
}else{
$message = sprintf( __( 'Successfully placed bid for &quot;%s&quot;!', 'wc_simple_auctions' ),$product_data -> get_title()  );
}
}

} else {
$message = sprintf( __( "Your bid was successful but you've been outbid for &quot;%s&quot;!", 'wc_simple_auctions' ),$product_data -> get_title()  );
}

wc_add_notice ( apply_filters('woocommerce_simple_auctions_placed_bid_message', $message,$product_id ) );

}

ส่วนนี่เป็น ajax ที่เราทำการเปลี่ยนค่าบางส่วนแล้วยกเว้นฟังก์ชั่นด้านบน

โค๊ด:
$('form.cart').submit(function(event) {
event.preventDefault();
      var current_user = jQuery("input[name=user_id]").length;
var error_div = jQuery('.archive-header .col-full .woocommerce .woocommerce-error').length;
if (current_user == 0) {
if (error_div == 0) {
jQuery('.archive-header .col-full .woocommerce').append('<ul class="woocommerce-error" role="alert"><li><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">กรุณาเข้าสู่ระบบ หรือ สมัครสมาชิก </font></font><a href="https://skxbay.com/?page_id=3677" class="button"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">เช้าสู่ระบบ / สมัครสมาชิก →</font></font></a></li></ul>');
}
}
// jQuery(".biddername").load(location.href + " .biddername");
    $.ajax({
      type: 'post',
      url: 'https://xxx.com',
      data: $('form').serialize(),
      success: function () {
      // getPriceAuction();
      // jQuery(".biddername").load(location.href + " .biddername");
      var your_bid = jQuery('.max-bid span.woocommerce-Price-amount').text();
      var current_bid = jQuery('.current-bid:eq(1) span.woocommerce-Price-amount').text();
      var product_name = jQuery('.product_title').text();

      if (your_bid != current_bid && current_user != 0) {
var div = jQuery('.archive-header .col-full .woocommerce .woocommerce-message').length;
if (div == 0) {
      jQuery('.archive-header .col-full .woocommerce').append('<div class="woocommerce-message" role="alert">สำเร็จสำหรับ '+product_name+'! ราคาคือ '+current_bid+'</div>');
jQuery('.archive-header .col-full .woocommerce').show().delay(5000).fadeOut();

}
else{

jQuery('.archive-header .col-full .woocommerce').show().delay(5000).fadeOut();
}
}



// clearInterval(refreshIntervalId);
      }
    });
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์