Created
June 25, 2022 10:24
-
-
Save robertuniqid/03f5868f996f2c53ba19e1bd6792b623 to your computer and use it in GitHub Desktop.
WordPress WooCommerce Subscriptions, Action Scheduler list actions as metabox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'add_meta_boxes', function() { | |
add_meta_box( | |
'wc-subscription-scheduled-actions', | |
__( 'WC Subscription Scheduled Actions' ), | |
function( $post ) { | |
$actions = as_get_scheduled_actions( [ | |
'args' => [ | |
'subscription_id' => $post->ID | |
] | |
] ); | |
if( empty( $actions ) ) { | |
echo '<p>' . __( 'Nothing found' ) . '</p>'; | |
return; | |
} | |
echo '<table class="wp-list-table widefat fixed striped table-view-list">'; | |
echo '<thead>'; | |
echo '<tr>'; | |
echo '<th>' . __( 'hook' ) . '</th>'; | |
echo '<th>' . __( 'args' ) . '</th>'; | |
echo '<th>' . __( 'Date' ) . '</th>'; | |
echo '</tr>'; | |
echo '</thead>'; | |
echo '<tbody>'; | |
foreach( $actions as $action ) { | |
$schedule = $action->get_schedule(); | |
if( $schedule instanceof \ActionScheduler_SimpleSchedule ) | |
$schedule = wp_date( get_option( 'date_format' ), $schedule->get_date()->getTimestamp() ); | |
echo '<tr>'; | |
echo '<td>' . esc_html( $action->get_hook() ) . '</td>'; | |
echo '<td>' . esc_html( json_encode( $action->get_args(), JSON_PRETTY_PRINT ) ) . '</td>'; | |
echo '<td>' . esc_html( $schedule ) . '</td>'; | |
echo '</tr>'; | |
} | |
echo '</tbody>'; | |
echo '</table>'; | |
}, | |
'shop_subscription' | |
); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment