Last active
February 5, 2021 06:10
-
-
Save picocodes/128e7a39741427175426d30612acb3fc to your computer and use it in GitHub Desktop.
Selling courses via GetPaid
This file contains 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 | |
function getpaid_example_link_to_item_course( $meta, $invoice ) { | |
// Abort if the invoice is not paid. | |
if ( ! $invoice->is_paid() ) { | |
return $meta; | |
} | |
foreach ( $invoice->get_items() as $item ) { | |
$course_id = get_post_meta( $item->get_id(), 'course_id', true ); | |
if ( ! empty( $course_id ) ) { | |
$course_name = sanitize_text_field( get_the_title( $course_id ) ); | |
$course_link = esc_url( get_the_permalink( $course_id ) ); | |
// Link to the course. | |
$meta[ 'course' ] = array( | |
'label' => $course_name, | |
'value' => sprintf( | |
'<a href="%s">%s</a>', | |
$course_link, | |
__( 'Enroll', 'invoicing' ) | |
), | |
); | |
} | |
} | |
return $meta; | |
} | |
add_filter( 'getpaid_invoice_meta_data', 'getpaid_example_link_to_item_course', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment