Thread Starter
Lucas
(@luquerias)
My working code:
$subscriptions = wcs_get_subscriptions_for_order($order_id, array( 'order_type' => 'any' ));
foreach( $subscriptions as $subscription_id => $subscription_obj )
{
$current_subs_id = $subscription_obj->get_id();
$subscriptiondate=$subscription_obj->get_date( 'start' );// This is current subscription id
$normalspainformat = date("d/m/Y", strtotime($subscriptiondate)+ 3600);
echo $normalspainformat;
}
I had to add 1 hour to the date because I was getting minus 1 hour…
Hi @luquerias,
I have tried every single method for getting the date of the active subscription and I haven’t been succesful in showing start date of subscription in my invoice… any idea about how to do it?
Using the code you left above as base, I have written this code snippet to display the subscription date after the order data on the PDF invoice:
/**
* PDF Invoices & Packing Slips for WooCommerce:
* Display the start date of the active subscription after the order data on the PDF invoice
*/
add_action( 'wpo_wcpdf_after_order_data', function( $document_type, $order ) {
if ( $document_type == 'invoice' && function_exists( 'wcs_get_subscriptions_for_order' ) ) {
// Only displays the field(s) if there is(are) a subscription(s)
if( $subscriptions = wcs_get_subscriptions_for_order( $order->get_id(), array( 'order_type' => 'any' ) ) ) {
foreach( $subscriptions as $subscription_id => $subscription_obj ) {
$current_subs_id = $subscription_obj->get_id();
$raw_subscription_date = $subscription_obj->get_date( 'start' );
$wp_subscription_date = wp_date( 'd/m/Y', strtotime( $raw_subscription_date ) );
}
?>
<tr class="subscription">
<th>Subscription Date (#<?php echo $current_subs_id; ?>):</th>
<td><?php echo $wp_subscription_date; ?></td>
</tr>
<?php
}
}
}, 10, 2 );
Please note that I have not tested the code above, so I have to ask you to test this code in a staging site, just in case.
If you haven’t worked with code snippets (actions/filters) or functions.php
before, read this guide: How to use filters
I had to add 1 hour to the date because I was getting minus 1 hour…
This is because you are using the date()
PHP function instead of the wp_date()
WordPress date function, that I have used in the code above.
Thread Starter
Lucas
(@luquerias)
Oh, great, many thanksss!
-
This reply was modified 7 months, 3 weeks ago by Lucas.