Skip to content

Instantly share code, notes, and snippets.

View ipokkel's full-sized avatar

Theuns Coetzee ipokkel

View GitHub Profile
<?php //do not copy
/**
* This code snippet checks if there's more than one item in the cart,
* finds the cheapest product and discounts it from the cart's total.
*/
function buyone_getone_free_discount() {
$contents = edd_get_cart_contents();
<?php //do not copy
/**
* Gets the next payment date and marks that as the expiration date for users.
*
* The "next payment" value is an estimate based on the billing cycle of the subscription and the last order date. It may be off from the actual recurring date set at the gateway, especially if the subscription was updated at the gateway.
*
* Remove the // on line 40 to run the update query.
*
* You can add this recipe to your site by creating a custom plugin
@ideadude
ideadude / fix-charset-for-pmpro-tables.sql
Created October 21, 2022 13:50
Update some PMPro DB tables to use UTF8 character sets.
# PMPro doesn't set the character set when creating its tables.
# So on install PMPro will use the default character set for your DB.
# In some cases this might be something like latin1, which will not
# work with special characters for non-latin languages, e.g. Hebrew.
# To fix this, you can update the character set on these tables using MySQL.
#
# IMPORTANT: Back up your DB (at least these tables) before running any queries.
ALTER TABLE wp_pmpro_membership_levels CONVERT TO CHARACTER SET utf8;
ALTER TABLE wp_pmpro_membership_levelmeta CONVERT TO CHARACTER SET utf8;
ALTER TABLE wp_pmpro_membership_ordermeta CONVERT TO CHARACTER SET utf8;
@ipokkel
ipokkel / add-billing-fields-to-user-profile-edit.php
Last active August 19, 2022 06:25
Add PMPro Billing Address fields to the user profile edit pages.
<?php
/**
* This will add billing fields to the administrative user profile edit page for administrators
* and on the frontend PMPro user Edit Profile page for members.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
@kimcoleman
kimcoleman / my_pmpro_remove_subscription_delay_for_renewals.php
Created July 11, 2022 14:07
Remove subscription delay for existing/past members. Charge them the full level price immediately at checkout. Update the level cost text.
<?php
/**
* Remove subscription delay for existing/past members.
*/
function my_pmpro_remove_subscription_delay_for_renewals() {
if ( is_admin() || ! is_user_logged_in() ) {
return;
}
$order = new MemberOrder();
<?php
/**
* Grant access to the back-end to certain user roles
*
* @param bool $prevent_admin_access
*
* @return bool
*/
function pmpro_grant_admin_access_to_dataanalyst( $prevent_admin_access ) {
if ( current_user_can( 'dataanalyst' ) ) {
<?php // do not copy this line.
/**
* Sponsored Members setup with child seat costs at checkout.
* SPONSOR SEAT + 4 seats 19.95 each
* + 5 to 19 @ 17.95
* + 20 to 39 @ $15.95
* + 40 to 79 @ 14.95
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
@ipokkel
ipokkel / readonly-on-profile-page-registration-field.php
Last active March 24, 2022 06:56
Set a custom registration field for PMPro Register Helper as readonly on the profile edit page.
<?php
/**
* Readonly field on profile edit page.
*
* Add profile_readonly to field and set to true.
*
* Fields with this option will remain editable if the field is empty, or
* if the current user can manage options (administrators), or
* if the current user is a membership manager that have a
* membership manager role.
@ipokkel
ipokkel / wp-mail-log.php
Last active March 10, 2022 08:45
Debugging email for WordPress. Logs mail erorrs,
<?php
/**
* WordPress Mail Debugger
*
* Log mail error message to debug-mail.log in wp-contents folder.
* Log mail error to debug.log in wp-contents folder.
*/
function wp_mail_error_log( $wp_error ) {
// Log mail error message to debug-mail.log file in wp-contents folder
@ipokkel
ipokkel / add-required-html-attribute.php
Last active May 9, 2022 16:21
Add required HTML attribute to required fields on PMPro Checkout Page.
<?php
/**
* Add HTML5 attribute required to all required PMPro fields.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/