Skip to content

Instantly share code, notes, and snippets.

@jdevalk
Created October 27, 2012 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdevalk/3966298 to your computer and use it in GitHub Desktop.
Save jdevalk/3966298 to your computer and use it in GitHub Desktop.
Retrieve the purchase ID based on the purchase key
<?php
/**
* Retrieve the purchase ID based on the purchase key
*
* @access public
* @since 1.2.3
*
* @param string $key the purchase key to search for
* @return int $order_id
*/
function edd_get_purchase_id_by_key( $key ) {
$meta_query = array(
array(
'key' => '_edd_payment_purchase_key',
'value' => $key
),
);
$payments = get_posts( array( 'meta_query' => $meta_query, 'post_type' => 'edd_payment' ) );
if ( count( $payments ) == 1 )
return $payments[0]->ID;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment