Skip to content

Instantly share code, notes, and snippets.

View contemplate's full-sized avatar

Ted Barnett contemplate

View GitHub Profile
@contemplate
contemplate / functions.php
Created December 11, 2023 17:31
WooCommerce Subscription: custom recurring total on checkout for a switch order with coupon applied
// Recurring Total line items
add_filter( 'woocommerce_subscription_price_string', 'wc_subscription_recurring_price_string', 10, 2 );
function wc_subscription_recurring_price_string( $subscription_string, $subscription_details ) {
if ( ( is_checkout() && ! is_wc_endpoint_url() ) ) {
$recurring_amount = $subscription_details['recurring_amount'];
//If this is a switch order with a Specific Coupon applied
if( WC()->cart->get_total( 'edit' ) == 0.00 && WC()->cart->has_discount( 'COUPON-NAME-HERE' ) && strpos($recurring_amount, '149.00') !== false){
return $recurring_amount . ' / 1st year<br>then $199.00 / year';
} else {
@contemplate
contemplate / fuunctions.php
Created October 28, 2023 14:43
WooCommerce: Only show Terms & Conditions at checkout for specific product category
add_filter('woocommerce_checkout_show_terms', 'remove_terms_and_conditions_checkbox_for_specific_category');
function remove_terms_and_conditions_checkbox_for_specific_category($show_terms) {
// Check if WooCommerce is active and the cart object is available
if (in_array('woocommerce/woocommerce.php', get_option('active_plugins')) && WC()->cart) {
// Define the product category slug to check for
$targeted_category_slug = 'your-product-cat-slug-here';
// Get the cart contents
$cart_items = WC()->cart->get_cart();
@contemplate
contemplate / functions.php
Created May 25, 2023 14:37
LearnDash: Bulk Enroll / Remove Users from Course from User List
/*----
Add Bulk Enroll / Remove options for each LearnDash Course in User List
---*/
function add_course_bulk_actions( $actions ) {
$courses = get_posts( array(
'post_type' => 'sfwd-courses',
'posts_per_page' => -1,
'post_status' => 'publish',
) );
@contemplate
contemplate / functions.php
Created April 27, 2023 20:34
AffiliateWP: Disable Recurring Refferals functions
/*-- Disable Recurring Refferals On New Affiliate --*/
function set_recurring_disabled_on_new_affiliate( $affiliate_id ) {
affwp_update_affiliate_meta( $affiliate_id, 'recurring_disabled', 1 );
}
add_action( 'affwp_insert_affiliate', 'set_recurring_disabled_on_new_affiliate' );
/*-- Bulk Disable Recurring Refferal on Affiliate List --*/
add_filter( 'affwp_affiliates_bulk_actions', 'bulk_disable_recurring_refferrals_name' );
function bulk_disable_recurring_refferrals_name($actions){
$actions['disablerecurring'] = 'Disable Recurring Refferals';
@contemplate
contemplate / affwp-store-credit-disable-per-affiliate-when-globally-enabled.php
Created April 26, 2023 12:46
AffiliateWP - Store Credit - Disable Store Credit Per Affiliate
<?php
/**
* Plugin Name: AffiliateWP - Store Credit - Disable Store Credit Per Affiliate
* Plugin URI: https://affiliatewp.com
* Description: Disable store credit per affiliate if store credit is globally enabled for all affiliates
* Author: Tunbosun Ayinla
* Author URI: https://affiliatewp.com
* Version: 1.0
*/
@contemplate
contemplate / bbp-reply-ajax.js
Created January 3, 2023 01:13
Buddyboss Jump to Reply fix
// When click on notification then move to particular reply.
moveToReply: function () {
if ( window.location.href.indexOf( '#post-' ) > 0 ) {
var varUrl = window.location.href.split( '#post-' );
var postID = varUrl && undefined !== varUrl[1] ? varUrl[1] : '';
if ( !postID ) {
return;
}
var scrollTop;
if ($('#wpadminbar').length){
@contemplate
contemplate / functions.php
Created December 20, 2022 21:36
AffiliateWP: Add WooCommerce Customer Name to Referrals Table & Affiliate Area
/**
* Add customer name to reference column of the referrals page
*/
function affwp_custom_wc_referrals_user_link( $reference, $referral ) {
if ( ! ( 'woocommerce' == $referral->context || class_exists( 'WC_Order' ) ) ) {
return $reference;
}
$order = wc_get_order( $referral->reference );
if( ! $order ){
@contemplate
contemplate / functions.php
Created December 18, 2022 22:12
AffiliateWP: Block WC Coupon if not referred - enhanced
add_action( 'woocommerce_coupon_options', 'affwp_only_referral_coupon_option' );
add_action( 'woocommerce_coupon_options_save', 'affwp_store_only_referral_coupon_option' );
add_filter( 'woocommerce_coupon_is_valid', 'affwp_custom_block_coupon_if_no_referrer', 10, 2 );
/**
* Add coupon option to enable only referral validity
*/
function affwp_only_referral_coupon_option() {
global $post;
@contemplate
contemplate / functions.php
Created November 19, 2022 19:58
Buddypress / Buddyboss exclude users from messaging & mention
//array of restricted user IDs
function bp_restricted_user_list(){
// These user's won't be able to receive the messages.
$restricted_user_ids = array( 102, 115, 220, 225 ); //Change these values to valid user IDs
return $restricted_user_ids;
}
/**
* Is user restricted from receiving message.
@contemplate
contemplate / metaboxes.php
Created November 11, 2022 23:53
MyBookTable get_user performance enhancement
<?php foreach( get_users( array( 'role__in' => array( 'administrator', 'editor', 'author', 'contributor' ) ) ) as $author) { ?>