반응형
WooCommerce - get_order()가 작동하지 않고 0을 반환합니다.
WooCommerce와 함께 온라인 샵을 만들고 있으며 데이터베이스에 보너스 포인트를 업데이트하는 기능을 추가하고 있습니다.absract-wc-payment-gateway.php
.
제가 하고 있는 일은 이렇습니다.
- 먼저 체크아웃 페이지에서 사용자는
place order
버튼을 누르면 메소드는 사용자에게 보너스 포인트를 주고 보너스 포인트를 뺀다.get-total()
, 그런 다음 데이터베이스로 업데이트하고 감사 페이지로 이동합니다.
- 그러면 감사 페이지가 데이터베이스에서 사용자의 보너스 포인트를 받게 됩니다.그리고 보너스 포인트 값을 2000으로 설정했습니다.따라서 이 경우 보너스 포인트는 총 포인트($50.00)에서 차감되어야 합니다.
여기 제 코드가 있습니다.플레이스오더 버튼을 클릭하면 실행됩니다.
global $woocommerce;
$order = new WC_Order($order_id);
$total = $order->get_total();
$bonusPoint -= (int)$total; //minus total price and calculate the latest bonus point
$updateSql = "UPDATE userdata02 SET bonusPoint ='" .$bonusPoint. "' WHERE userID = 2147483647";
mysqli_query($link, $updateSql);// update to an int column
if(mysqli_query($link, $updateSql)) {
echo "Record updated successfully";
} else {
echo "Error update record: <>" . mysqli_error($link);
}
사용자가 플레이스 버튼을 클릭하면 메소드를 호출합니다.
public function get_return_url( $order = null ) {
if ( $order ) {
//$message = "wrong answer";
//echo "<script type='text/javascript'>alert('$message');</script>";
$return_url = $order->get_checkout_order_received_url();
} else {
$return_url = wc_get_endpoint_url( 'order-received', '', wc_get_page_permalink( 'checkout' ) );
}
if ( is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes' ) {
$return_url = str_replace( 'http:', 'https:', $return_url );
}
self::reducePoints(); //Call reducePoints();
return apply_filters( 'woocommerce_get_return_url', $return_url, $order );
}
소스 코드:reducePoints()
초록-WC-지불-게이트웨이에서 89호선이 나옵니다.php
그get_total()
작동하지 않고 0을 반환합니다.
내가 뭘 잘못하고 있는 거지?
다음에 대한 개체를 만들어야 합니다.$order
함께 사용할 수 있습니다.시도해 보기:
global $woocommerce;
$order = new WC_Order($order_id);
$total = $order->get_total(); //Get the total price of the order.
$bonusPoints -= (int)$total; //calculate the new bonusPoints
업데이트 1:이는 내부 데이터 오류를 해결하는 것에 불과합니다.우리는 그것을 작동시키기 위해 필요합니다.
참고: 제거 가능global $woocommerce;
전에$order = new WC_Order($order_id);
왜냐하면 이미 포함되어 있기 때문입니다.public function reducePoints( ){
업데이트 2 - 좋은 트랙:
내 코드 제거:
global $woocommerce;
$order = new WC_Order($order_id);
그럼 코드 89번 줄에 그냥 추가해요.$order
다음 위치:
public function reducePoints( $order ){
global $woocommerce;
// ...
이것이 효과가 있어서 정말 기쁩니다.긴 탐색이었어요...
언급URL : https://stackoverflow.com/questions/38304515/woocommerce-get-order-doesnt-work-and-it-returns-zero
반응형
'programing' 카테고리의 다른 글
키 누르기 이벤트 후 jQuery.val() AFTER 이벤트를 받으려면 어떻게 해야 합니까? (0) | 2023.09.14 |
---|---|
Android의 상태 표시줄 높이 (0) | 2023.09.14 |
.crt와 .key 파일로 .jks를 만드는 것이 가능합니까? (0) | 2023.09.14 |
Angular에서 라우터를 사용하는 구성 요소를 단위 테스트하려면 어떻게 해야 합니까? (0) | 2023.09.14 |
포스트 텍스트에서 블록 따옴표 제거 - Wordpress (0) | 2023.09.14 |