/**
 * Get taxation rate
 *
 * @since 1.3.3
 * @param bool $country
 * @param bool $state
 * @return mixed|void
 */
function edd_get_tax_rate($country = false, $state = false)
{
    $rate = (double) edd_get_option('tax_rate', 0);
    $user_address = edd_get_customer_address();
    if (empty($country)) {
        if (!empty($_POST['billing_country'])) {
            $country = $_POST['billing_country'];
        } elseif (is_user_logged_in() && !empty($user_address)) {
            $country = $user_address['country'];
        }
        $country = !empty($country) ? $country : edd_get_shop_country();
    }
    if (empty($state)) {
        if (!empty($_POST['state'])) {
            $state = $_POST['state'];
        } elseif (!empty($_POST['card_state'])) {
            $state = $_POST['card_state'];
        } elseif (is_user_logged_in() && !empty($user_address)) {
            $state = $user_address['state'];
        }
        $state = !empty($state) ? $state : edd_get_shop_state();
    }
    if (!empty($country)) {
        $tax_rates = edd_get_tax_rates();
        if (!empty($tax_rates)) {
            // Locate the tax rate for this country / state, if it exists
            foreach ($tax_rates as $key => $tax_rate) {
                if ($country != $tax_rate['country']) {
                    continue;
                }
                if (!empty($tax_rate['global'])) {
                    if (!empty($tax_rate['rate'])) {
                        $rate = number_format($tax_rate['rate'], 4);
                    }
                } else {
                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) {
                        continue;
                    }
                    $state_rate = $tax_rate['rate'];
                    if (0 !== $state_rate || !empty($state_rate)) {
                        $rate = number_format($state_rate, 4);
                    }
                }
            }
        }
    }
    if ($rate > 1) {
        // Convert to a number we can use
        $rate = $rate / 100;
    }
    return apply_filters('edd_tax_rate', $rate, $country, $state);
}
<?php
/**
 * This template is used to display the profile editor with [edd_profile_editor]
 */
global $current_user;

if ( is_user_logged_in() ):
	$user_id      = get_current_user_id();
	$first_name   = get_user_meta( $user_id, 'first_name', true );
	$last_name    = get_user_meta( $user_id, 'last_name', true );
	$display_name = $current_user->display_name;
	$address      = edd_get_customer_address( $user_id );

	if ( edd_is_cart_saved() ): ?>
		<?php $restore_url = add_query_arg( array( 'edd_action' => 'restore_cart', 'edd_cart_token' => edd_get_cart_token() ), edd_get_checkout_uri() ); ?>
		<div class="edd_success edd-alert edd-alert-success"><strong><?php _e( 'Saved cart', 'edd'); ?>:</strong> <?php printf( __( 'You have a saved cart, <a href="%s">click here</a> to restore it.', 'edd' ), esc_url( $restore_url ) ); ?></div>
	<?php endif; ?>

	<?php if ( isset( $_GET['updated'] ) && $_GET['updated'] == true && ! edd_get_errors() ): ?>
		<div class="edd_success edd-alert edd-alert-success"><strong><?php _e( 'Success', 'edd'); ?>:</strong> <?php _e( 'Your profile has been edited successfully.', 'edd' ); ?></div>
	<?php endif; ?>

	<?php edd_print_errors(); ?>

	<?php do_action( 'edd_profile_editor_before' ); ?>

	<form id="edd_profile_editor_form" class="edd_form" action="<?php echo edd_get_current_page_url(); ?>" method="post">
		<fieldset>
			<span id="edd_profile_name_label"><legend><?php _e( 'Change your Name', 'edd' ); ?></legend></span>
			<p id="edd_profile_name_wrap">
				<label for="edd_first_name"><?php _e( 'First Name', 'edd' ); ?></label>
 /**
  *
  * @param unknown $payment        	
  * @param string $edd_receipt_args        	
  */
 public function edd_osgi_action_payment_receipt_after_table($payment, $edd_receipt_args = null)
 {
     if ($this->osgipub_osgi_debug) {
         echo "<p>debug: this is the action after table</p>\n";
     }
     if (isset($payment) && edd_is_payment_complete($payment->ID)) {
         $meta = get_post_meta($payment->ID);
         if ($this->osgipub_osgi_debug) {
             echo "<p>debug: Payment vardump=";
             var_dump($payment);
             echo "</p>\n";
             echo "<p>debug: Payment metadata vardump=";
             var_dump($meta);
             echo "</p>\n";
         }
         // same $cart = edd_get_payment_meta_cart_details( $payment->ID, true );
         $downloads = edd_get_payment_meta_cart_details($payment->ID, true);
         $edd_payment_post_id = $payment->ID;
         $edd_payment_user_id = (string) $meta['_edd_payment_user_id'][0];
         $edd_payment_customer_id = (string) $meta['_edd_payment_customer_id'][0];
         //TODO REMOVED BECAUSE NOT BEING GENERATED $edd_payment_number = ( string ) $meta ['_edd_payment_number'] [0];
         $edd_payment_number = $edd_payment_post_id;
         $edd_payment_purchase_key = (string) $meta['_edd_payment_purchase_key'][0];
         // see easy-digital-downloads/templates/history-downloads.php
         // add_query_arg( 'payment_key', edd_get_payment_key( $post->ID ), edd_get_success_page_uri() )
         if ($downloads) {
             $display_licence_table = false;
             // check if any downloads are osgi licenced
             foreach ($downloads as $download) {
                 if ($this->is_osgi_licenced($download['id'])) {
                     $display_licence_table = true;
                 }
             }
             if ($display_licence_table) {
                 echo "<div id=\"osgi_licence_list_table\" class=\"osgi_licence_list\">\n";
                 echo "<h3>OSGi Licences</h3>\n";
                 echo "<p>One of more of your purchased downloads have associated OSGi Licences.<BR>To generate your licences select the links below.</p>\n";
                 echo "<table>\n";
             }
             // used to set change licence name for multiple downloads
             $download_no = 0;
             foreach ($downloads as $download) {
                 // Skip over Bundles. Products included with a bundle will be displayed individually
                 if (edd_is_bundled_product($download['id'])) {
                     continue;
                 }
                 // if not osgi licenced bundle skip
                 if (!$this->is_osgi_licenced($download['id'])) {
                     continue;
                 }
                 $download_no++;
                 $price_id = edd_get_cart_item_price_id($download);
                 $download_files = edd_get_download_files($download['id'], $price_id);
                 $name = get_the_title($download['id']);
                 // quantity used to handle multiple licences per download
                 for ($quantity = 1; $quantity <= $download['quantity']; $quantity++) {
                     if (isset($edd_payment_number)) {
                         // start of table row
                         echo "  <tr>\n";
                         echo "    <td>\n";
                         // product id string from download
                         // contains maven unique id of product to which this licence applies
                         $edd_osgiProductIdStr = get_post_meta($download['id'], '_edd_osgiProductIdStr', true);
                         // try loading modified LicenceMetadataSpecStr from this product efinition and apply to licence post
                         $edd_modified_osgiLicenceMetadataSpecStr = get_post_meta($download['id'], '_edd_modified_osgiLicenceMetadataSpecStr', true);
                         // Retrieve and append the price option name
                         if (!empty($price_id)) {
                             $name .= ' - ' . edd_get_price_option_name($download['id'], $price_id, $payment->ID);
                         }
                         // product name - payment number - download number
                         $licence_post_title = $name . ' - ' . $edd_payment_number . '-' . $download_no . '-' . $quantity;
                         // remove whitepsace
                         $licence_post_name = preg_replace('/\\s+/', '', $licence_post_title);
                         if ($this->osgipub_osgi_debug) {
                             echo "<p>debug: download [id]=" . $download['id'] . '</p>\\n';
                             if (!isset($edd_osgiProductIdStr)) {
                                 echo "<p>debug: from download edd_osgiProductIdStr not set for download [id]=" . $download['id'] . '</p>\\n';
                             } else {
                                 echo "<p>debug: from download edd_osgiProductIdStr=";
                                 echo $edd_osgiProductIdStr;
                                 echo "</p>\n";
                             }
                             echo "<p>debug: payment name=";
                             echo $name;
                             echo "</p>\n";
                             echo "<p>debug: licence_post_title=";
                             echo $licence_post_title;
                             echo "</p>\n";
                             echo "<p>debug: licence_post_name=";
                             echo $licence_post_name;
                             echo "</p>\n";
                             echo "<p>debug: edd_payment_number=";
                             echo $edd_payment_number;
                             echo "</p>\n";
                         }
                         $found_post = null;
                         if ($posts = get_posts(array('name' => $licence_post_name, 'post_type' => 'osgi_licence_post', 'post_status' => 'publish', 'posts_per_page' => 1))) {
                             $found_post = $posts[0];
                         }
                         // Now, we can do something with $found_post
                         if (!is_null($found_post)) {
                             if ($this->osgipub_osgi_debug) {
                                 echo "<p>debug: we found the licence post=";
                                 echo $found_post->ID;
                                 echo "</p>\n";
                             }
                             echo '<a href="' . get_post_permalink($found_post->ID) . '" >Link to Licence: ' . $licence_post_title . '</a>';
                             echo "\n";
                         } else {
                             // get post with payment number metadata OR create post with metadata
                             $post = array('post_content' => '<p>DO NOT EDIT: You can only view or change this licence post by using View Post.</p>', 'post_name' => $licence_post_name, 'post_title' => $licence_post_title, 'post_status' => 'publish', 'post_type' => 'osgi_licence_post', 'ping_status' => 'closed', 'comment_status' => 'closed');
                             // Default is the option 'default_comment_status', or 'closed'.
                             // 'post_category' => [ array(<category id>, ...) ] // Default empty.
                             // 'tags_input' => [ '<tag>, <tag>, ...' | array ] // Default empty.
                             // 'tax_input' => [ array( <taxonomy> => <array | string> ) ] // For custom taxonomies. Default empty.
                             // 'page_template' => '../edd-downloads-as-osgi.php' // Requires name of template file, eg template.php. Default empty.
                             $newpost_id = wp_insert_post($post);
                             // setting product id for licence
                             // update_post_meta ( $newpost_id, 'edd_osgiProductIdStr', 'org.opennms.co.uk/org.opennms.co.uk.newfeature/0.0.1-SNAPSHOT' );
                             update_post_meta($newpost_id, 'edd_osgiProductIdStr', $edd_osgiProductIdStr);
                             // apply modified metadata to this licence post
                             update_post_meta($newpost_id, '_edd_modified_osgiLicenceMetadataSpecStr', $edd_modified_osgiLicenceMetadataSpecStr);
                             // setting customer metadata - not yet used in the template
                             update_post_meta($newpost_id, 'edd_payment_customer_id', $edd_payment_customer_id);
                             update_post_meta($newpost_id, 'edd_payment_user_id', $edd_payment_user_id);
                             // setting edd_osgiLicencee information
                             $f_name = (string) get_user_meta($edd_payment_user_id, 'first_name', true);
                             $first_name = isset($f_name) ? $f_name : "";
                             $l_name = (string) get_user_meta($edd_payment_user_id, 'last_name', true);
                             $last_name = isset($l_name) ? $l_name : "";
                             $address = "";
                             $addr = edd_get_customer_address($edd_payment_user_id);
                             if (isset($addr)) {
                                 $address = implode(", ", $addr);
                             }
                             $edd_osgiLicencee = $first_name . ", " . $last_name . ", " . $address;
                             update_post_meta($newpost_id, 'edd_osgiLicencee', $edd_osgiLicencee);
                             // for reverse lookup of post id of the associated payment
                             update_post_meta($newpost_id, 'edd_payment_post_id', $edd_payment_post_id);
                             if ($this->osgipub_osgi_debug) {
                                 echo "<p>debug: we created a new licence post=";
                                 echo $newpost_id;
                                 echo "</p>\n";
                             }
                             echo '<a href="' . get_post_permalink($newpost_id) . '" >Link to Licence: ' . $licence_post_title . '</a>';
                             echo "\n";
                         }
                         echo "    </td>\n";
                         echo "  </tr>\n";
                     }
                 }
             }
             if ($display_licence_table) {
                 echo "</table>\n";
                 echo "</div> <!-- div id=osgi_licence_list_table -->";
             }
         }
     } else {
         echo '<p>payment not set</p>\\n';
     }
     if ($this->osgipub_osgi_debug) {
         if (isset($edd_receipt_args)) {
             echo "<p>debug: edd_receipt_args vardump=";
             var_dump($edd_receipt_args);
             echo "</p>\n";
         } else {
             echo '<p>debug: edd_receipt_args not set</p>\\n';
         }
     }
 }