Skip to content

Instantly share code, notes, and snippets.

View topmask's full-sized avatar
🤩
Out sick

Allen Smith topmask

🤩
Out sick
View GitHub Profile
@topmask
topmask / Fix for “Sold Individually” Products
Created October 27, 2021 05:18
Fix for “Sold Individually” Products
add_filter( 'woocommerce_product_add_to_cart_url', 'elftoy_fix_for_individual_products', 10, 2 );
function elftoy_fix_for_individual_products( $add_to_cart_url, $product ){
if( $product->get_sold_individually() // if individual product
&& WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $product->id ) ) // if in the cart
&& $product->is_purchasable() // we also need these two conditions
&& $product->is_in_stock() ) {
$add_to_cart_url = wc_get_checkout_url();
}
@topmask
topmask / Disable bad robots from registering
Last active October 27, 2021 05:37
Disable bad robots register
function add_security_question_fields() {
$num1=rand(1,9);
$num2=rand(2,9);
echo "<p><label for='math' class='small'>Captcha:$num1 + $num2 = ? </label><input type='text' name='sum' class='input' value='' size='25'>"
."<input type='hidden' name='num1' value='$num1'>"
."<input type='hidden' name='num2' value='$num2'></p>";}
add_action('register_form','add_security_question_fields');
add_action( 'register_post', 'add_security_question_validate', 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email, $errors){
@topmask
topmask / checkout remove coupon form
Created October 27, 2021 05:24
checkout remove coupon form
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
@topmask
topmask / disable automatic updates
Created October 27, 2021 05:27
disable automatic updates
add_filter( 'plugins_auto_update_enabled', '__return_false' );
add_filter( 'themes_auto_update_enabled', '__return_false' );
define( 'automatic_updater_disabled', true );
define( 'wp_auto_update_core', false );
@topmask
topmask / Enable preview thumbnail for webp image files
Last active October 27, 2021 05:33
Enable upload for webp image files
function webp_is_displayable($result, $path) {
if ($result === false) {
$displayable_image_types = array( IMAGETYPE_WEBP );
$info = @getimagesize( $path );
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $displayable_image_types)) {
$result = false;
} else {
@topmask
topmask / Login Link To Go To The WooCommerce Account Page
Created October 27, 2021 07:52
How To Update The Login Link To Go To The WooCommerce Account Page
@topmask
topmask / remove “Archive:”, “Category:”
Created October 27, 2021 12:31
How to remove “Archive:”, “Category:” etc. pre-title inserts in Archive Titles
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
@topmask
topmask / 从WordPress完全删除jQuery
Created October 29, 2021 11:14
如何从WordPress完全删除jQuery
/** * Completely Remove jQuery From WordPress */
function my_init() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', false);
}
}
add_action('init', 'my_init');
@topmask
topmask / 安装最新的jQuery版本
Created October 29, 2021 11:17
安装最新的jQuery版本
/** * Install latest jQuery version 3.4.1. */
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"), false);
wp_enqueue_script('jquery');
}
@topmask
topmask / 从WordPress管理仪表板上完全删除jQuery
Created October 29, 2021 11:18
从WordPress管理仪表板上完全删除jQuery
/** * Completely Remove jQuery From WordPress Admin Dashboard */
add_action('wp_enqueue_scripts', 'no_more_jquery');
function no_more_jquery(){
wp_deregister_script('jquery');
}