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 / functions.php
Created February 20, 2018 11:23
Remove tabs from WooCommerce
// Remove the tabs from woocommerce - posted by Robin Scott of Silicon Dales @ https://silicondales.com/tutorials/woocommerce-tutorials/remove-tab-woocommerce/
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
@robin-scott
robin-scott / functions.php
Created February 6, 2018 09:47
Automatically complete woocommerce orders when paid
// Automatically complete woocommerce orders on successful payment (skip "processing") - Robin Scott for SiliconDales.com
add_action( 'woocommerce_thankyou', 'sd_woocommerce_auto_complete_order' );
function sd_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}
@robin-scott
robin-scott / functions.php
Created January 31, 2018 09:56
Remove woocommerce description tab
// add this to functions.php, a custom plugin, or a snippets plugin to remove the description tab in woocommerce
// by Robin Scott of Silicon Dales - full info at https://silicondales.com/tutorials/woocommerce-tutorials/remove-description-tab-woocommerce/
add_filter( 'woocommerce_product_tabs', 'sd_remove_product_tabs', 98 );
function sd_remove_product_tabs( $tabs ) {
unset( $tabs['description'] );
return $tabs;
}
@robin-scott
robin-scott / functions.php
Created December 29, 2017 16:09
Remove Gravity forms fields in a specific form
// Robin Scott added this here for use in SiliconDales.com, but the snippet comes from Gravity Forms docs, here: https://docs.gravityforms.com/gform_export_fields/
add_filter( 'gform_export_fields', function ( $form ) {
// only limit the fields available for export form form ID 3
if ( $form['id'] == 3 ) {
// array of field IDs I never want to see on the export page
$fields_to_remove = array(
'payment_amount',
'payment_date',
'payment_status',
'transaction_id',
@robin-scott
robin-scott / finctions.php
Created December 29, 2017 16:03
Remove unwanted fields from Gravity Forms exports
// Remove unwanted fields from Gravity Forms export - updated by Robin Scott of Silicon Dales
add_filter( 'gform_export_fields', function ( $form ) {
// array of field IDs I never want to see on the export page
$fields_to_remove = array(
'payment_amount',
'payment_date',
'payment_status',
'transaction_id',
'user_agent',
'ip',
@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>
');
}
}
?>
@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 } ?>
// 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 / 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;
}
@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');