Skip to content

Instantly share code, notes, and snippets.

View gareth-gillman's full-sized avatar

gareth-gillman

View GitHub Profile
@gareth-gillman
gareth-gillman / functions.php
Created April 10, 2019 18:44
get product price
// Add Shortcode
function gg_price_shortcode( $atts ) {
$product = wc_get_product( $post_id );
echo $product->get_price_html();
}
add_shortcode( 'product-price', 'gg_price_shortcode' );
@gareth-gillman
gareth-gillman / functions.php
Created February 5, 2019 16:28
Woo Checkout Spam
function wcs_checkout_field( $checkout ) {
woocommerce_form_field(
'wcs_buyer_gift',
array(
'type' => 'text',
'class' => array('wcs-field form-row-wide'),
),
$checkout->get_value( 'wcs_buyer_gift' )
);
}
@gareth-gillman
gareth-gillman / functions.php
Created August 19, 2018 19:02
WordPress create page on user register
function gg_new_user_page( $user_id ) {
$user_info = get_userdata( $user_id );
$user_login = $user_info->user_login;
$newpage = array(
'post_title' => wp_strip_all_tags( $user_login ),
'post_type' => 'page',
'post_content' => '',
'post_status' => 'publish',
//'page_template' => 'template-blog.php'
<?php
$server_date = get_date();
$date = strtotime( $server_date );
$hour = date('H', $date);
if( $hour > 9 && $hour < 20 ) {
echo 'it's between 9am and 8pm';
}
@gareth-gillman
gareth-gillman / functions.php
Created July 13, 2018 21:56
WordPress Hide admin elements
function prefix_admin_hide_contents() {
$admin_user = wp_get_current_user();
if( $admin_user->ID != '5' ) {
echo '<style>';
echo '.element { display: none; }';
echo '</style>';
}
}
add_filter( 'admin_head', 'prefix_admin_hide_contents' );
@gareth-gillman
gareth-gillman / functions.php
Last active July 5, 2018 00:38
Hide columns based on user role
function my_manage_columns( $columns ) {
$user = wp_get_current_user();
if ( in_array( 'author', 'editor', (array) $user->roles ) ) {
unset($columns['column-name']);
return $columns;
}
}
function my_column_init() {
add_filter( 'manage_posts_columns' , 'my_manage_columns' );
@gareth-gillman
gareth-gillman / functions.php
Created June 11, 2018 21:17
add button to woocommerce category
function gg_cat_btn() {
if( is_tax( 'product_cat' ) ) {
add_action( 'woocommerce_after_shop_loop_item_title', 'gg_readmore_btn' );
}
}
add_filter( 'woocommerce_after_shop_loop_item', 'gg_cat_btn' );
function gg_readmore_btn() {
echo '<a class="cat-btn" href="'.get_permalink().'">'.__( 'Book / Get quote!', 'your-plugin' ).'</a>';
}
function set_compression( $compression ) {
return 100;
}
add_filter( 'jpeg_quality', 'set_compression', 999 );
add_filter( 'wp_editor_set_quality', 'set_compression', 999 )
@gareth-gillman
gareth-gillman / functions.php
Created April 14, 2018 11:50
Woocommerce limit product short description
function wpdocs_custom_excerpt_length( $length ) {
if( is_singular( 'product' ) ) {
return 20;
}
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
@gareth-gillman
gareth-gillman / functions;php
Created March 23, 2018 12:02
Add link below Single Add to Cart button in Woocommerce
function single_cart_extra_btn() {
$btn = '<a class="btn" href="http://www.myurl.com">myurl</a>';
return $btn;
}
add_action( 'woocommerce_single_product_summary', 'single_cart_extra_btn', 35 );