Created
October 29, 2021 07:16
-
-
Save picocodes/d05f56ce70beab5c1b37533fc0648ef8 to your computer and use it in GitHub Desktop.
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 | |
// If next year is not yet here... | |
if ( (int) date( 'Y' ) < 2022 ) { | |
// ... then give a 50% discount on the initial item price... | |
add_filter( 'wpinv_get_initial_item_price', function( $price ) { | |
global $wpdb; | |
// ... unless he/she is not a first time customer. | |
if ( ! get_current_user_id() ) { | |
return $price; | |
} | |
$paid_invoices = $wpdb->get_var( | |
$wpdb->prepare( | |
"SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'wpi_invoice' AND post_author = %d", | |
get_current_user_id() | |
) | |
); | |
return $paid_invoices > 0 ? $price : $price * 0.5; // Give 50% discount if a first time customer. | |
}, 10, 2 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment