2016-07-11 4 views
6

देता है मैं WooCommerce के साथ एक ऑनलाइन दुकान बना रहा हूं और मैं एक फ़ंक्शन जोड़ रहा हूं जो absract-wc-payment-gateway.php में मेरे डेटाबेस में बोनस प्वाइंट अपडेट करेगा।WooCommerce - get_order() काम नहीं करता है और यह शून्य

यहाँ मैं क्या कर रहा हूँ है:

  1. सबसे पहले, चेकआउट पृष्ठ पर, उपयोगकर्ताओं place order बटन पर क्लिक करें और फिर विधि get-total() के साथ उपयोगकर्ताओं को बोनस अंक और शून्य से बोनस अंक मिल जाएगा, और उसके बाद डेटाबेस में अद्यतन करें और धन्यवाद पृष्ठ पर जाएं।

enter image description here

  1. फिर, का शुक्रिया पेज डेटाबेस से उपयोगकर्ता की बोनस अंक मिल जाएगा। और मैं 2000 के लिए बोनस अंक मान सेट तो इस मामले में, बोनस अंक ($ 50.00) कुल अंकों शून्य से

enter image description here

यहाँ मेरी कोड है होना चाहिए।

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); 
} 

स्रोत कोड: abstract-WC-Payment-Gateway.php

से reducePoints() लाइनों 89 get_total() काम नहीं करता है और यह शून्य लौटाता है।

मैं क्या गलत कर रहा हूं?

+0

क्या आपने त्रुटि लॉग जांच की है कि यह आंतरिक त्रुटि क्यों हो रही है? –

उत्तर

3

आपको के लिए get_total() के साथ उपयोग करने के लिए एक ऑब्जेक्ट बनाने की आवश्यकता है। इस प्रयास करें:

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 

Update1: यह सिर्फ आंतरिक डेटा त्रुटि को सुलझाने है। क्योंकि पहले से ही public function reducePoints(){


Update2 में शामिल है आप $order = new WC_Order($order_id); से पहले global $woocommerce; निकाल सकते हैं - अच्छा ट्रैक:: हम $order_id यह काम पाने के लिए प्राप्त करने की आवश्यकता ...

नोट

मेरा कोड निकालें:

global $woocommerce; 
$order = new WC_Order($order_id); 

फिर अपने कोड की पंक्ति 89 में सिर्फ में $order जोड़ें:

public function reducePoints($order){ 
    global $woocommerce; 

    // ... 

बहुत खुश है कि इस काम करता है ... यह एक लंबी खोज रहा था ...

+0

मैंने 'ट्रैक: 2' का उपयोग करके समस्या को ठीक किया! तुमसे बहुत प्यार करता हूँ <3 – Capslock10

संबंधित मुद्दे