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 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 / 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';