Forum Replies Created

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thread Starter deve42

    (@deve42)

    Hi Drazen,

    Gladly left a well-deserved review. Thank you so much for your help, looking forward to the next release!

    Deve

    Thread Starter deve42

    (@deve42)

    Thank you so much Drazen! Your code is what I need, I had to add the priority and number of parameters at the end but that’s all I need to fix to get it to work.

    Here is the code to include the first & last names for anyone else who needs it:

    add_filter('lmfwc_rest_api_pre_response', function($method, $route, $data) {
        // Check if we are on the correct route (perhaps also verify the $method?)
        if ($route === 'v2/licenses/activate/{license_key}' || $route === 'v2/licenses/validate/{license_key}') {
            // Order ID is present in the $data array
            $orderId = $data['orderId'];
    
            // Retrieve the customer email
            $order = wc_get_order($orderId);
    
            $data['customerFirstName'] = $order->get_billing_first_name();
    	$data['customerLastName'] = $order->get_billing_last_name();
    	$data['customerEmail'] = $order->get_billing_email();
        }
        
        return $data;
    }, 10, 3);

    Btw, $method seems to repeat what $data is, any reason why I need to verify it?

    Cheers!

    • This reply was modified 5 years, 4 months ago by deve42.
    Thread Starter deve42

    (@deve42)

    Thank you again, Drazen. Sorry for being a noob with the WP/Woocommerce frameworks, I am still unable to figure out how to hook into your code.

    To get the buyer’s email (possibly with name), here is my function:

    function getBuyerMeta($orderID) {
       if (empty($orderID)) {
          $result->error = "Missing orderID!";
       } else {
          if (is_numeric($orderID)) {
             $order = wc_get_order($orderID);
             if ($order) {
                $order_data = $order->get_data();
                if ($order_data) {
                   $billing = $order_data['billing'];
                   $result->fname = $billing['first_name'];
                   $result->lname = $billing['last_name'];
                   $result->email = $billing['email'];
                } else {
                   $result->error = "No such order data: ". $orderID;
                }
             } else {
                $result->error = "No such order: ". $orderID;
             }
          } else {
             $result->error = "Invalid orderID!";
          }
       }
       
       return $result;
    }

    How do I grab the orderID from your API (activation / validation), and integrate it with this function or have the function directly hooked into lmfwc_rest_api_pre_response?

    • This reply was modified 5 years, 4 months ago by deve42.
    Thread Starter deve42

    (@deve42)

    Hi Drazen,

    Hope you had a nice vacation! I’ve been testing some custom code to get the buyer meta data and it’s working ok but it’s not integrated into your plugin and require a separate call to the server.

    If all I need is to have your plugin API return the buyer’s email during validation or activation, what would I need to add to use the hook?

    Thread Starter deve42

    (@deve42)

    Btw, in the Settings screen:

    PUT – v2/licenses/activate/{license_key}

    should be:

    GET – v2/licenses/activate/{license_key}

    Thread Starter deve42

    (@deve42)

    Thanks for your reply, Drazen.

    Sorry I have no idea what the composer dependencies are. Probably better to let you integrate all these so I’m not messing things up.

    Enjoy your vacation!

    Thread Starter deve42

    (@deve42)

    I’m comfortable using the development version because my site is under construction and is not live. However, I’m not familiar with the WordPress framework and it’s been a while since I coded in PHP (it’s changed a lot since).

    Was thinking I might write a function to query the DB for the user info but it might be better to have everything integrated within your plugin if you already have it under development.

    My confusion is which API function to call or do I need to add my own code in Setup.php?

    Thanks!

    Thread Starter deve42

    (@deve42)

    I’ll try to figure out a solution. Thanks.

    Thread Starter deve42

    (@deve42)

    Thanks Drazen, wow that’s wonderful!

    I’m a bit lost with how these hooks work or how I call them… Any pointers?

    Really appreciate your help! Can’t wait for your next release.

    Thanks,
    Deve

Viewing 9 replies - 16 through 24 (of 24 total)