I use woocommerce subscriptions and software license manager master plugin, i want to display the licenses generated by the software license manager master plugin on the view-subscription page, now the licenses created by software license manager master plugin are displayed on view-order page, this function is written in the software license manager master plugin to be displayed on view-order page :
/**
* Display values on the order details page
*/
function slm_order_details($order) {
global $wpdb;
$items = $order->get_items();
$licences = array();
foreach ($items as $item_key => $item_details) {
$product = $item_details->get_product();
if ( $product->is_type('subscription') && wcs_order_contains_subscription( $order, 'parent' ) && $order->has_status('completed') ) {
if ($lic_keys = wc_get_order_item_meta($item_details->get_id(), '_slm_lic_key', false)) {
$lic_types = wc_get_order_item_meta($item_details->get_id(), '_slm_lic_type', false);
$licences = array_map(function ($keys, $types) {
return array(
'lic_key' => $keys,
'lic_type' => $types
);
}, $lic_keys, $lic_types);
}
}
}
if ($licences) {
echo '
<h2 >' . __('License details', 'softwarelicensemanager') . '</h2>
<table >
<thead>
<tr>
<th >' . __('License key', 'softwarelicensemanager') . '</th>
<th >' . __('Type', 'softwarelicensemanager') . '</th>
</tr>
</thead>
<tbody>
';
foreach ($licences as $lic_row) {
echo '
<tr >
<td >
' . $lic_row['lic_key'] . ' - <a href="' . get_permalink(wc_get_page_id('myaccount')) . '/my-licenses"> ' . __('view my licenses', 'softwarelicensemanager') . '</a>
</td>
<td >
' . $lic_row['lic_type'] . '
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
}
} add_action('woocommerce_order_details_after_order_table', 'slm_order_details', 10, 1);
i found a position on view-subscription page :
do_action( 'woocommerce_subscription_totals_table', $subscription );
i change woocommerce_order_details_after_order_table
to this woocommerce_subscription_totals_table
, but nothing is displayed on view-subscription page
what is wrong with my work? any answer from you will certainly bring my thanks
CodePudding user response:
/**
* Display values on the subscription details page
*/
function subscription_order_details($subscription) {
global $wpdb;
$order = $subscription->get_parent();
$items = $order->get_items();
$licences = array();
foreach ($items as $item_key => $item_details) {
$product = $item_details->get_product();
if ( $product->is_type('subscription') && wcs_order_contains_subscription( $order, 'parent' ) && $order->has_status('completed') ) {
if ($lic_keys = wc_get_order_item_meta($item_details->get_id(), '_slm_lic_key', false)) {
$lic_types = wc_get_order_item_meta($item_details->get_id(), '_slm_lic_type', false);
$licences = array_map(function ($keys, $types) {
return array(
'lic_key' => $keys,
'lic_type' => $types
);
}, $lic_keys, $lic_types);
}
}
}
if ($licences) {
echo '
<h2 >' . __('License details', 'softwarelicensemanager') . '</h2>
<table >
<thead>
<tr>
<th >' . __('License key', 'softwarelicensemanager') . '</th>
<th >' . __('Type', 'softwarelicensemanager') . '</th>
</tr>
</thead>
<tbody>
';
foreach ($licences as $lic_row) {
echo '
<tr >
<td >
' . $lic_row['lic_key'] . ' - <a href="' . get_permalink(wc_get_page_id('myaccount')) . '/my-licenses"> ' . __('view my licenses', 'softwarelicensemanager') . '</a>
</td>
<td >
' . $lic_row['lic_type'] . '
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
}
}
add_action('woocommerce_subscription_totals_table', 'subscription_order_details', 10, 1);