Skip to content

Instantly share code, notes, and snippets.

Avatar

Theuns Coetzee ipokkel

View GitHub Profile
View mypmpro-woo-discount-variable-pricing.php
<?php //do not copy
/**
* This recipe will either add a fee or discount to specific variations of a Woo
* product based on the level that the user holds.
*
* In the below example, variation ID 107 should have level 1 and a fee of 1500 will be added.
* Variation ID 108 requires a level 2 and applies a discount of 8
*
* You can add this recipe to your site by creating a custom plugin
@ideadude
ideadude / my_upload_size_limit_for_non_admins.php
Created December 9, 2022 15:46
Limit non-admin/editor file uploads to 2mb with WordPress
View my_upload_size_limit_for_non_admins.php
<?php
/**
* Limit non-admin/editor file uploads to 2mb
* We check the upload_files capability,
* so anyone with access to the Media Library
* can upload files at the PHP/server set max.
*
* 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.
View mypmpro-assign-membership-level-from-variable-product.php
<?php //do not copy
/**
* This recipe associates a membership level with a Variable product's variation.
* You can specify that Variation A should get Level 1 and Variation B should get Level 2.
*
* Add variations/levels to the array in Line 31
*
* Use of this code recipe requires that the PMPro WooCommerce Add On is active.
*
View buy-one-get-one-free-discount-easy-digital-downloads.php
<?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();
View mypmpro-set-next-payment-date-expiration-date.php
<?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
@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.
View add-billing-fields-to-user-profile-edit.php
<?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.
View my_pmpro_remove_subscription_delay_for_renewals.php
<?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();
View pmpro_block_dashboard-grant-certain-user-roles.php
<?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' ) ) {
@kimwhite
kimwhite / my_init_override_sponsored_members_pricing_update.php
Last active December 14, 2022 09:53 — forked from ideadude/my_init_override_sponsored_members_pricing_update.php
PMPro Sponsored Members Example Variable seat pricing.
View my_init_override_sponsored_members_pricing_update.php
<?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.
View readonly-on-profile-page-registration-field.php
<?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.