Skip to content

Instantly share code, notes, and snippets.

View techskilled's full-sized avatar

Tech Skilled techskilled

View GitHub Profile
@techskilled
techskilled / gist:394d3b5b1175ff2a3cb8
Last active August 29, 2015 14:19
Create a WordPress Database Error Page
<?php
// INFORM GOOGLE SITES TEMP DOWN
$protocol = $_SERVER["SERVER_PROTOCOL"];
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) $protocol = 'HTTP/1.0';
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 600' );
$temp = mysql_error();
$url = curPageURL();
@techskilled
techskilled / Deleteusers.sql
Created August 22, 2016 16:12
WooCommerce SQL to delete users who have no orders or posts
DELETE from wp_users where wp_users.ID not in (
SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user'
) AND wp_users.ID not in (
select distinct(post_author) from wp_posts
);
delete from wp_usermeta where wp_usermeta.user_id not in (select ID from wp_users);
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('16');
return $cat_args;
}
@techskilled
techskilled / functions.php
Created August 24, 2016 10:00
WooCommerce change out of stock text to sold
add_filter('woocommerce_get_availability', 'availability_filter_func');
function availability_filter_func($availability)
{
$availability['availability'] = str_ireplace('Out of stock', 'Sold', $availability['availability']);
return $availability;
}
@techskilled
techskilled / functions.php
Created August 24, 2016 10:22
WooCommerce Replace text : Shop page title
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function woo_shop_page_title( $page_title ) {
if( 'Shop' == $page_title) {
return "Place your new shop page title here";
}
}
@techskilled
techskilled / functions.php
Last active March 19, 2019 11:30
WooCommerce Text Replace: Change / Rename product tab text
/**
* @snippet WooCommerce Text Replace: Change / Rename product tab text
* @code https://techskilled.co.uk/knowledgebases/woocommerce-single-product-change-rename-product-tab-text
* @author https://techskilled.co.uk
*/
function techskilled_renameproduct_tab($tabs) {
$tabs['description']['title'] = 'Extra Information';
/** DISBALE WP-ADMIN FROM NON ADMIN : SOBER MEDIA 13/08/2016 **/
add_action('admin_init', 'no_mo_dashboard');
function no_mo_dashboard() {
$isAjax = (defined('DOING_AJAX') && true === DOING_AJAX) ? true : false;
//if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
if(!$isAjax) {
if(!current_user_can('administrator')) {
wp_redirect('http://www.example.com/'); exit;
/**
* Remove Cart Stage
* @see: http://stackoverflow.com/questions/15592633/woocommerce-add-to-cart-button-redirect-to-checkout
*/
add_filter( 'add_to_cart_redirect', 'redirect_to_checkout' );
function redirect_to_checkout() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
@techskilled
techskilled / snippets.php
Last active March 23, 2019 15:42
Woocommerce - Single Product – Edit Only 1 left in stock
/**
* @snippet single Product - Edit Only 1 left in stock
* @code https://techskilled.co.uk/snippets/woocommerce-edit-only-1-left-in-stock-single-product-page
* @author https://techskilled.co.uk
*/
function techskilled_edit_left_stock( $text, $product ) {
$stock = $product->get_stock_quantity();
if ( $product->is_in_stock() && $product->managing_stock() && $stock <= get_option( 'woocommerce_notify_low_stock_amount' ) ) $text .= '. Get it today to avoid 5+ days restocking delay!';
return $text;
@techskilled
techskilled / gist:e6bd55ce11dbcfaeea87c53e2aae5170
Last active March 23, 2019 15:42
Woocommerce - Single Product - Add Content After Add to Cart
/**
* @snippet Woocommerce - Single Product - Add Content After Add to Cart
* @code https://techskilled.co.uk/snippets/woocommerce-add-content-after-add-to-cart-single-product-page
* @author https://techskilled.co.uk
*/
function show_content_after_add_to_cart() {
echo '&lt;div style=&quot;clear: both; padding-top: 20px;&quot;&gt;&lt;a style=&quot;font-weight: 600;&quot; href=&quot;#doit&quot;&gt;OR Doing it yourself?&lt;/a&gt;&lt;/div&gt; ';