我使用WooCommerce订阅和软件许可管理器主插件,我想在查看-订阅页面上显示软件许可管理器主插件生成的许可,现在在查看-订购页面上显示软件许可管理器主插件创建的许可,这个函数写在软件许可管理器主插件中,在查看-订购页面上显示:
/**
* 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 class="woocommerce-order-details__title">' . __('License details', 'softwarelicensemanager') . '</h2>
<table class="woocommerce-table woocommerce-table--order-details shop_table order_details">
<thead>
<tr>
<th class="woocommerce-table__product-name product-name">' . __('License key', 'softwarelicensemanager') . '</th>
<th class="woocommerce-table__product-table product-total">' . __('Type', 'softwarelicensemanager') . '</th>
</tr>
</thead>
<tbody>
';
foreach ($licences as $lic_row) {
echo '
<tr class="woocommerce-table__line-item order_item">
<td class="woocommerce-table__product-name product-name">
' . $lic_row['lic_key'] . ' - <a href="' . get_permalink(wc_get_page_id('myaccount')) . '/my-licenses"> ' . __('view my licenses', 'softwarelicensemanager') . '</a>
</td>
<td class="woocommerce-table__product-total product-total">
' . $lic_row['lic_type'] . '
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
}
} add_action('woocommerce_order_details_after_order_table', 'slm_order_details', 10, 1);
我在查看订阅页面上找到了一个职位:
do_action( 'woocommerce_subscription_totals_table', $subscription );
我将woocommerce_order_details_after_order_table
更改为woocommerce_subscription_totals_table
,但在查看-订阅页面上没有显示任何内容
我的工作出了什么问题?你的任何答复一定会给我带来感谢