Skip to content

Instantly share code, notes, and snippets.

@grantambrose
grantambrose / gist:2182669ddc29ab71f948811d6e2b450e
Last active February 13, 2024 04:38
Redirect from Woo Product to associated Course (bi-directional field setup)
// this function redirects users to the course they purchased
// when they try to access the WooCommerce product that sold the course
// as they don't need to see the sales page anymore, they want the lessons
add_action( 'template_redirect', 'c_redirect_to_purchased_course' );
function c_redirect_to_purchased_course() {
// if it's not a woo product page, return and do nothing
if( !is_product() ) return;
// get related courses
$c_products_related_courses = get_field('c_products_related_courses');
@grantambrose
grantambrose / gist:7a8a09e217013c4627241342433dd361
Created February 12, 2024 02:49
Redirect to Course if customer purchased a Woo Product
function c_has_purchased_product_ids($product_ids){
// debugging
// echo "Customer has bought product ids: " . $ids;
if ( ! $product_ids ) return false;
$current_user = wp_get_current_user();
// always show for admins
if(current_user_can('administrator')) return true;
if(is_array($product_ids)){
@grantambrose
grantambrose / 1functions.php
Created October 25, 2016 02:14
Create a custom 404 page using Beaver Builder
<?php get_header(); ?>
<?php
// replace 404-error-page below with the slug of your own 404 Beaver Builder Template
echo do_shortcode('[fl_builder_insert_layout slug="404-error-page"]'); ?>
<?php get_footer(); ?>
@grantambrose
grantambrose / 1functions.php
Last active October 25, 2016 17:41
Hide page elements in Beaver Builder using URL parameters
// Add our custom Body Classes based on the URL Parameters
add_filter('body_class', 'bb_body_class');
function bb_body_class($classes) {
if( isset($_GET['plan']) ){
$plan_param = $_GET['plan'];
if($plan_param == 'partner'){
$classes[] .= 'pricing-partner';
}
}
else{
@grantambrose
grantambrose / 1nav-right.php
Last active September 13, 2016 01:15
Change the width of the logo and menu sections in the Beaver Builder Theme
<div class="col-md-4 col-sm-12 fl-page-header-logo-col">
<div class="fl-page-header-logo" itemscope="itemscope" itemtype="http://schema.org/Organization">
<a href="<?php echo home_url(); ?>" itemprop="url"><?php FLTheme::logo(); ?></a>
</div>
</div>
<div class="fl-page-nav-col col-md-8 col-sm-12">
@grantambrose
grantambrose / 1functions.php
Created September 12, 2016 22:23
WordPress: Change the main menu on different pages
// Conditionally change menus
add_filter( 'wp_nav_menu_args', 'bb_wp_nav_menu_args' );
function bb_wp_nav_menu_args( $args = '' ) {
// change the menu in the Header menu position
if( $args['theme_location'] == 'header' && is_page('1159') ) {
$args['menu'] = '32'; // 32 is the ID of the menu we want to use here
}
return $args;
}
@grantambrose
grantambrose / 1single.php
Last active August 31, 2016 22:41
Disable the Blog Sidebar ONLY on Single Posts
<?php FLTheme::sidebar('left'); ?>
<div class="fl-content <?php FLTheme::content_class(); ?>">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php get_template_part('content', 'single'); ?>
<?php endwhile; endif; ?>
</div>
<?php FLTheme::sidebar('right'); ?>
@grantambrose
grantambrose / 1style.css
Last active August 31, 2016 18:05
10 ways you can better your website's typography today
/* Change Typography for Medium Devices and up */
@media only screen and (min-width: 992px) {
/* ----------------------
TYPOGRAPHY
---------------------- */
body{font-size:20px;}
h1{font-size:2.5em;}
h2{font-size:2em;}
h3{font-size:1.7em;}
h4{font-size:1.5em;}
@grantambrose
grantambrose / style.css
Last active August 30, 2016 18:02
Sticky the Top Bar in the Beaver Builder Theme
/* Sticky the Top Bar in the Beaver Builder Theme ONLY for medium devices and large devices
- Change the 992px breakpoint to whatever you like */
@media only screen and (min-width: 992px) {
/* Change the 35px value below to the heigt of your Top Bar */
.fl-page-bar { position: fixed; width: 100%; z-index: 10; }
.fl-page-header-fixed { margin-top: 35px;}
.fl-page-header-primary { padding-top: 35px; }
}
@grantambrose
grantambrose / 1photo.php
Last active August 30, 2016 19:19
Overriding a default Beaver Builder module to create a unique Blog Post Layout
'align' => array(
'type' => 'select',
'label' => __('Alignment', 'fl-builder'),
'default' => 'center',
'options' => array(
'left' => __('Left', 'fl-builder'),
'center' => __('Center', 'fl-builder'),
'right' => __('Right', 'fl-builder'),
'full-width' => __('Full-width', 'fl-builder')
)