I am using the WooCommerce Subscriptions plugin to manage recurring orders.
But I want my customers to see custom data, that I add to all new subscriptions, on their subscriptions details page.
I add a variable for the customers baby name, which I add as _baby_name
in the subscriptions data post_meta data like this:
/**
* Triggered after a new subscription is created.
*
* @since 2.2.22
* @param WC_Subscription $subscription
*/
function action_wcs_create_subscription( $subscription ) {
// Get ID
$subscription_id = $subscription->get_id();
update_post_meta( $subscription_id, '_baby_name', get_current_user_id() );
}
add_action( 'wcs_create_subscription', 'action_wcs_create_subscription', 10, 1 );
For testing purposes, I just set the value to be get_current_user_id()
.
To present this custom data on the customers frontend, I have tried to modify the subscription-details.php file:
wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/templates/myaccount/subscription-details.php
I added a row in the top of my subscription_details table, above the status row like this:
<tbody>
<tr>
<td><?php esc_html_e( 'Baby Name', 'woocommerce-subscriptions' ); ?></td>
<td><?php echo esc_html( $subscription.'baby_name' ); ?></td>
</tr>
<tr>
<td><?php esc_html_e( 'Status', 'woocommerce-subscriptions' ); ?></td>
<td><?php echo esc_html( wcs_get_subscription_status_name( $subscription->get_status() ) ); ?></td>
</tr>
But in my new row for Baby Name, I just get all data associated with $subscriptions:
What should I use instead of $subscription.'_baby_name'
to pull the value of _baby_name
, and show it in the table?