Skip to content

Instantly share code, notes, and snippets.

View robin-scott's full-sized avatar
🏠
Working from home

Rob Scott robin-scott

🏠
Working from home
View GitHub Profile
@robin-scott
robin-scott / my-account.php
Last active May 2, 2016 22:38 — forked from mclanecreative/my-account.php
Adds Tabs to WooCommerce "My Account" page. Instructions: add my-account.php to your /woocommerce/myaccount/ folder. Next, add the CSS to your child theme's style.css file. 11/25/2015 - Added tab6 for Event Espresso WP User Integration. Next challenge is to include Sensei My Courses & Pippin's AffiliateWP on these tabs.
<?php
/**
* My Account page
*
* @author WooThemes
* @edited by McLane Creative
* @package WooCommerce/Templates
* @version 3.1.0
*/
@robin-scott
robin-scott / custom-my-account-endpoint.php
Created May 2, 2016 22:54 — forked from claudiosanches/custom-my-account-endpoint.php
Example of custom My Account endpoint.
<?php
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $endpoint = 'my-custom-endpoint';
@robin-scott
robin-scott / gist:341922bc2cdfd4c734618e71cb471b88
Created August 31, 2017 21:38
WooCommerce Gateway Stripe Icon Remover
// Rob Scott makes the icon for diners and jcb disappear pfft like magic
function rs_removed_icon( $icons ) {
$icons = str_replace( '<img src="[your absolute url to...]/assets/images/icons/credit-cards/jcb.svg" alt="JCB" width="32" style="margin-left: 0.3em" />', '', $icons );
$icons = str_replace( '<img src="[your absolute url to...]/assets/images/icons/credit-cards/diners.svg" alt="Diners" width="32" style="margin-left: 0.3em" />', '', $icons );
return $icons;
}
add_filter( 'woocommerce_gateway_icon', 'rs_removed_icon');
//Add a checkout padlock and alternative message in the Pay Now button - by Robin Scott of Silicon Dales
add_filter( 'woocommerce_order_button_text', 'sd_custom_order_button_text' );
function sd_custom_order_button_text() {
return __( 'Checkout Securely &#128274;', 'woocommerce' );
}
@robin-scott
robin-scott / style.css
Last active November 29, 2017 10:59
Remove box around links in Storefront
a:focus,
.focus a {
outline: none !important;
}
@robin-scott
robin-scott / functions.php
Created December 1, 2017 13:10
Shows the current time in London, when a shortcode is called in WordPress
// Add a shortcode to dispay [now_time] for the time in Europe/London - by Robin Scott of Silicon Dales
function sd_now_time_formated($atts) {
date_default_timezone_set("Europe/London");
$i = date('g:i A');
return $i;
}
add_shortcode('now_time', 'sd_now_time_formated');
@robin-scott
robin-scott / gist:4c8ea6bba196129172d2bd876b637b8a
Last active February 12, 2019 10:41
Make woocommerce not allow a product user has purchased before to be purchased again
// posted by Robin Scott https://silicondales.com/tutorials/woocommerce-tutorials/woocommerce-tutorial-allow-users-purchase-items/ - prevent user adding item to cart if they bought it before...
add_filter('woocommerce_add_to_cart_validation','sd_bought_before_woocommerce_add_to_cart_validation',20, 2);
function sd_bought_before_woocommerce_add_to_cart_validation($valid, $product_id){
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id)) {
wc_add_notice( __( 'ERROR MESSAGE GOES HERE SORRY YOU CANNOT BUY ANYTHING TWICE OKAY!!', 'woocommerce' ), 'error' );
$valid = false;
}
return $valid;
}
// Added by Robin Scott of Silicon Dales here to demonstrate My Account / login links: https://silicondales.com/tutorials/woocommerce/display-woocommerce-account-page-link-logged-users-login-register-link-not-logged/
<?php if ( is_user_logged_in() ) { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woocommerce'); ?>"><?php _e('My Account','woocommerce'); ?></a>
<?php }
else { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woocommerce'); ?>"><?php _e('Login / Register','woocommerce'); ?></a>
<?php } ?>
@robin-scott
robin-scott / page.php
Created December 19, 2017 22:19
Hide stuff on front page - WordPress PHP code example
// the gist below will hide stuff on the frontpage in wordpress, when added to a theme template file... see https://silicondales.com/tutorials/wordpress-tutorials/code-hide-content-front-page-wordpress/
<?php if( !is_front_page() ) {?>
// hide this stuff
<?php } ?>
@robin-scott
robin-scott / page.php
Created December 19, 2017 22:22
Hide Yoast breadcrumbs on frontpage of WordPress
//this gist will hide Yoast breadcrumbs on the blog front page (the home page if you made this a page)
// see https://silicondales.com/tutorials/wordpress-tutorials/code-hide-content-front-page-wordpress/
<?php if( !is_front_page() ) {
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('
<p id="breadcrumbs">','</p>
');
}
}
?>