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 April 10, 2024 14:24
WPC Product Bundles for WooCommerce Shortcode
// Hook into init action to set bundled_position to "no" if the shortcode is used
function wpc_set_bundled_position() {
add_filter('woosb_get_setting', 'wpc_disable_bundled_position', 10, 3);
}
// Function to set bundled_position to "no" if the shortcode is used
function wpc_disable_bundled_position($setting, $name, $default) {
// Check if the shortcode is used on the current page
if ($name === 'bundled_position' && wpc_is_show_bundled_shortcode_used()) {
return 'no';
@contemplate
contemplate / functions.php
Created March 15, 2024 16:28
Divi Theme: Replace Top Header with a Header Sidebar Area
// Register custom sidebar
function custom_register_sidebars() {
register_sidebar( array(
'name' => 'Header',
'id' => 'header_sidebar',
'description' => 'Widgets in this area will be shown in the header.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
@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 February 8, 2024 04:40
WooCommerce Memberships: exclude post loops on forced public pages
// Initialize the global flag on the wp action hook
add_action('wp', 'initialize_force_public_page_flag');
function initialize_force_public_page_flag() {
global $is_force_public_page, $wp_query;
$is_force_public_page = false;
if (!empty($wp_query->queried_object_id)) {
$is_force_public_page = get_post_meta($wp_query->queried_object_id, '_wc_memberships_force_public', true) === 'yes';
}
}
@contemplate
contemplate / functions.php
Created February 3, 2024 18:27
ACF Relational Field Shortcode Expanded
/**
* Output an ACF post relationship field type using a shortcode:
* [acf_relationship_field field="field_name" show="all"]
* You can also pass `post_id` as an attribute
*
* Show parameter accepts any comma seperated combination of: all, title, title_linked, date, author, post_excerpt, post_content
*
* Works with Post Object and Relationship fields, when the return
* format is both post object and post ID
*
@contemplate
contemplate / functions.php
Created January 15, 2024 16:19
AffiliateWP: limit leaderbaord to specific affiliate group
add_filter( 'affwp_leaderboard_defaults', 'group_affwp_leaderboard_defaults', 10 );
function group_affwp_leaderboard_defaults( $defaults ) {
$defaults['connected_to'] = array(
'get_connectable' => 'affiliate',
'where_connectable' => 'group',
'where_id' => 2, // ID of the affiliate group
'where_group_type' => 'affiliate-group',
);
return $defaults;
@contemplate
contemplate / functions.php
Created January 12, 2024 19:39
LearnDash Course Grid v1: Add Scheduled Date Lock for Lessons & Topics
//For Use with Elementor Lesson List & topic List Grid widgets
add_filter( 'learndash_course_grid_html_output', 'learndash_course_grid_add_avilable_date', 10, 4 );
function learndash_course_grid_add_avilable_date( $data, $post, $shortcode_atts, $user_id ) {
if ( 'sfwd-topic' == $post->post_type || 'sfwd-lessons' == $post->post_type ) {
$course_id = $shortcode_atts['course_id'];
if( $course_id ){
$attributes = learndash_get_course_step_attributes( $post->ID, $course_id, $user_id );
$is_sample = ( isset( $lesson->sample ) ? $post->sample : false );
$ld_lesson_has_access = sfwd_lms_has_access( $post->ID, $user_id );
$ld_available_date = learndash_course_step_available_date( $post->ID, $course_id, $user_id, true );
@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) { ?>
@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 {