Skip to content

Instantly share code, notes, and snippets.

View andrewlimaza's full-sized avatar

Andrew Lima andrewlimaza

View GitHub Profile
@andrewlimaza
andrewlimaza / add-order-payment-details-to-pmpro-pdf.php
Created February 15, 2024 19:05
Paid Memberships Pro PDF Invoices Plugin - Show card digits, expiration and order status.
<?php
/**
* Add custom variables to PDF template editor to show some more order information.
* To add this code to your site, please visit - https://yoohooplugins.com/customize-wordpress/
*/
function my_pmpro_pdf_card_details( $data_array, $user, $order_data ) {
$data_array['{{card}}'] = esc_html( $order_data->accountnumber );
$data_array['{{card_expiration}}'] = esc_html( $order_data->expirationmonth . '/' . $order_data->expirationyear );
$data_array['{{order_status}}'] = esc_html( $order_data->status );
return $data_array;
@andrewlimaza
andrewlimaza / pmpro-network-subsite-dont-redirect.php
Created January 10, 2024 13:43
Stop the Multisite Membership Add On from redirecting to the main site on the network
<?php
/**
* This stops the logic of redirecting members to the main site on the network when viewing a PMPro page on the subsite.
* This is useful for cases where you need to still access these membership pages on the subsite.
*
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
remove_filter( 'pmpro_url', 'pmpro_multisite_pmpro_url', 10, 4 );
remove_action( 'init', 'pmpro_multisite_get_parent_site_pages', 20 );
@andrewlimaza
andrewlimaza / pmpro-kosovo-country.php
Last active January 4, 2024 12:19
Add Kosovo as country to Paid Memberships Pro
<?php
/**
* Add Kosovo as a country to the Paid Memberships Pro countries dropdown.
* To add this code to your site, please follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_add_kosovo_country( $countries ) {
$countries['XK'] = 'Kosovo';
asort( $countries ); // Sort it alphabetically again.
return $countries;
}
@andrewlimaza
andrewlimaza / my-pmpro-cycle-period-reword-member-shortcode.php
Created January 2, 2024 07:47
Reword cycle period output from the pmpro_member shortcode to read better.
<?php
/**
* Change "Month" to "Monthly" etc when using `[pmpro_member field="membership_cycle_period"]` shortcode.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_reword_cycle_period_member_shortcode( $r, $user_id, $field ) {
// This isn't the cycle period field, let's bail.
if ( $field !== 'cycle_period' ) {
return $r;
@andrewlimaza
andrewlimaza / show-content-for-specific-course-pmpro.php
Created January 2, 2024 07:04
[my_pmpro_show_course_content] shortcode to show lesson content for a particular course ID.
<?php
/**
* Show lesson content for a specific course ID using a shortcode.
* Use [my_pmpro_show_course_content id="5"] to display the lessons for course ID of 5.
* Tweak this output to your needs further, as this is used as a starting template.
*
* To add this code to your site, please follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_show_course_content( $atts ) {
@andrewlimaza
andrewlimaza / next-payment-date-pmpro-shortcode.php
Created December 27, 2023 08:05
Next Payment Date PMPro Shortcode
<?php
/**
* Show the next payment date via shortcode [pmpro_next_payment_shortcode]
* Add this code to your site by following - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_next_payment_shortcode() {
$next_payment = pmpro_next_payment();
if ( $next_payment ) {
$output = date_i18n( get_option( 'date_format' ), $next_payment );
@andrewlimaza
andrewlimaza / pmpro-orders-table-custom-columns.php
Created December 4, 2023 07:48
Custom order column for Paid Memberships Pro (New hooks).
<?php
/**
* Create a custom order column header and value for the PMPro Orders table.
* Add this code to your site by following - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Create a custom column in the orders table of PMPro.
function my_pmpro_add_column_header_order( $columns ) {
$columns['my_custom_column'] = __( 'My Custom Column', 'pmpro' );
return $columns;
@andrewlimaza
andrewlimaza / pmpro-pdf-invoices-discount-codes.php
Created December 1, 2023 14:45
Add {{discount_code}} to Paid Memberships Pro PDF Invoices
<?php
/**
* Add the variable {{discount_code}} to the PDF to show what discount code was used for the order.
* Follow this guide to add this custom code to your site - https://yoohooplugins.com/customize-wordpress/
*/
function my_pmpro_add_discount_code_to_pdf( $variables, $user, $order_data ) {
// Get the discount code used for the order and assign it to {{discount_code}}
$order = new MemberOrder( $order_data->code );
$discount_code = $order->getDiscountCode();
@andrewlimaza
andrewlimaza / add-shortcode-non-member-text.php
Created October 30, 2023 11:17
Allow shortcode functionality inside the non-member or logged-out non-member text Paid Memberships Pro shows.
<?php
/**
* Adds the ability to use shortcodes inside the Non-Member text Paid Memberships Pro displays on restricted content.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_allow_shortcodes_non_member_text() {
add_filter( 'pmpro_non_member_text_filter', 'shortcode_unautop' );
add_filter( 'pmpro_non_member_text_filter', 'do_shortcode' );
add_filter( 'pmpro_not_logged_in_text_filter', 'shortcode_unautop' );
add_filter( 'pmpro_not_logged_in_text_filter', 'do_shortcode' );
@andrewlimaza
andrewlimaza / wll-shortcode-sample.php
Created October 10, 2023 17:45
WordPress When Last Login output user's login via shortcode.
<?php
/**
* Show last login timestamp shortcode. Use [wll_show_login] on any page or post where needed.
* Add this code to your site by following this guide - https://yoohooplugins.com/customize-wordpress/
*/
function wll_show_login_shortcode() {
// Get the current user's ID
$user_id = get_current_user_id();
// Check if the user is logged in