Skip to content

Instantly share code, notes, and snippets.

View BoyetDgte's full-sized avatar

IRC on VPS BoyetDgte

View GitHub Profile
@BoyetDgte
BoyetDgte / Custom WooCommerce login
Last active August 9, 2019 12:30
Custom WooCommerce login and dashboard button
add_filter( 'wp_nav_menu_items', 'custom_login_dashboard', 10, 2 );
function custom_login_dashboard( $items, $args ) {
if (is_user_logged_in() && $args->primary-menu == 'primary') { //change your theme registered menu name to suit - currently for DIVI theme
$items .= '<li><a class="mydashboard" href="'. get_permalink( wc_get_page_id( 'myaccount' ) ) .'">My Dashboard</a></li>' . '<style> #top-header { background: #7a0101!important;} #main-header, #main-footer, #footer-bottom { background: black!important;}</style>';
//the style is changing the theme's color once you are logged in
}
elseif (!is_user_logged_in() && $args->primary-menu == 'primary') {//change your theme registered menu name to suit
$items .= '<li><a class="mydashboard" href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
}
@BoyetDgte
BoyetDgte / .scpt
Created June 12, 2019 10:07
Apple script for emailing multiple accounts in Mac Mail
set {firstName, eAddress} to getData()
repeat with i from 1 to count firstName
tell application "Mail"
activate
set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"Great new! We are now offering Radio Mobile Apps for Android and iOS here at Internet Radio Cast on VPS"}
tell mymail
make new to recipient at beginning of to recipients with properties {address:item i of eAddress}
delay 5
set content to "Hi " & item i of firstName & "
@BoyetDgte
BoyetDgte / gist:dc72a2cd0dfe6220e2ac411791574e69
Created February 26, 2020 11:48
Modify texts in WooCommerce Subscription plugin
// change the “for” to "up to for"
function change_subscription_product_string( $subscription_string, $product, $include ) {
if( $include ){
$subscription_string = str_replace('for', 'for up to', $subscription_string);
}
return $subscription_string;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'change_subscription_product_string', 10, 3 );
@BoyetDgte
BoyetDgte / gist:6318b93f95aba42f33f9c76891f01045
Created February 26, 2020 11:55
Adding DEFER or ASYNC in JS scripts via functions.php
// Single script
function make_script_defer( $tag, $handle, $src ){
if ( 'wp_register_script-name-1' != $handle ) {
return $tag;
}
return str_replace( '<script', '<script defer', $tag );
}
add_filter( 'script_loader_tag', 'make_script_defer', 10, 3 );
@BoyetDgte
BoyetDgte / gist:9798a923f98dc35e29a30a7dc49561fb
Created February 26, 2020 11:58
Add a Class or ID in Wordpress specific menu <a> tag instead of the <li> tag using jQuery
// class name example
jQuery( "#menu-item-30142 a" ).ready( function( $ ){
$( "#menu-item-30142 a" ).addClass("class-name");
});
// #menu-item-30142 a is the element id with <a> tag
@BoyetDgte
BoyetDgte / gist:d0627b1e81e2929e95314d09be9425b5
Created February 26, 2020 12:07
Redirect users to a different URL(default is My Account) after WooCommerce login.
// After login, users (customers and subscribers only) are redirected to the "Video Library" page -> get_permalink( $post = 6913 );
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
// video library URL
$videolibrary = get_permalink( $post = 6913 );
@BoyetDgte
BoyetDgte / exclude_scripts
Last active August 7, 2020 03:50
Exclude Scripts (Google tags, FB Pixel) on all blog posts and the blog page on a specific Multisite. Filter is added on Head, Footer and Body tag.
function excluding_blogs_header() {
// exclude from Posts Page (blog) page and all blog posts on the Main site (multisite)
if( !is_single() && !is_home() && 1 === get_current_blog_id() ) {
$code = "<script> Your script here </script>";
} else {
  $code = null;
}
  echo $code;
}
@BoyetDgte
BoyetDgte / functions.php
Last active November 5, 2020 04:03
Modify date range for BuddyPress Xprofile Custom Fields Type - Birthdate Selector (Starting at year 1930)
function custom_bxcft_birthdate_year($html, $type, $day, $month, $year, $field_id, $date) {
if($type == 'year'){
$html = '<option value=""' . selected( $year, '', false ) . '>----</option>';
for ( $i = date('Y', time()-60*60*24); $i > 1929; $i-- ) {
$html .= '<option value="' . $i .'"' . selected( $year, $i, false ) . '>' . $i . '</option>';
}
}
return $html;
@BoyetDgte
BoyetDgte / course_complete.php
Created March 25, 2021 08:49
Redirect to any page after LearnDash course is completed
add_action('learndash_course_completed', 'course_completed', 10, 1);
function course_completed( $data ) {
$course_id = $data['course']->ID;
$slug_url = get_post_field( 'post_name', $course_id );
if ($course_id) {
// After creating a "congrats" parent page and a child page with the same slug from the course.
// More info here https://www.radiocastvps.com/how-to-redirect-to-a-page-after-completing-a-learndash-course/
wp_redirect(site_url("/congrats/$slug_url"));