Skip to content

Instantly share code, notes, and snippets.

View carlosvarela's full-sized avatar

Carlos Varela carlosvarela

View GitHub Profile
@carlosvarela
carlosvarela / functions.php
Created May 24, 2019 18:30
only let purchase one specific product in woocommerce
/**
* Restricts which products can be added to the cart at the same time. Tested
* with WooCommerce up to version 2.5.
*
* HOW TO USE THIS CODE
* 1. Add the code to the bottom of your theme's functions.php file (see https://www.skyverge.com/blog/add-custom-code-to-wordpress/).
* 2. Set the IDs of the products that are allowed to be added to the cart at the same time.
* 3. Amend the message displayed to customers when products are unavailable after the specified
* products have been added to the cart (see function woocommerce_get_price_html(), below).
*
<?php
/**
* Add a custom body class for a specific page template
* Add the following to your theme functions.php file.
*/
add_filter( 'body_class', 'custom_class' );
function custom_class( $classes ) {
if ( is_page_template( 'templates/page-contact.php' ) ) {
$classes[] = 'contact';
}
@carlosvarela
carlosvarela / functions.php
Created May 2, 2018 01:59
Displays product attributes in the top right of the single product page in Woocommerce
/**
* Displays product attributes in the top right of the single product page.
*
* @param $product
*/
function display_attributes( $product ) {
global $product;
global $post;
@carlosvarela
carlosvarela / functions.php
Created March 26, 2018 18:58
WordPress Redirect Home After Logout
/* add in your functions.php */
add_action('wp_logout','auto_redirect_after_logout');
function auto_redirect_after_logout(){
wp_redirect( home_url() );
exit();
}

Gradient shadow in pure CSS

alt text

HTML
<button>Let's Go !</button>
@carlosvarela
carlosvarela / functions.php
Created February 28, 2018 02:19
Clear WordPress Header
// =========================================================================
// REMOVE JUNK FROM HEAD
// =========================================================================
remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
remove_action('wp_head', 'wp_generator'); // remove wordpress version
remove_action('wp_head', 'feed_links', 2); // remove rss feed links (make sure you add them in yourself if youre using feedblitz or an rss service)
remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links
remove_action('wp_head', 'index_rel_link'); // remove link to index page
@carlosvarela
carlosvarela / functions.php
Created February 19, 2018 00:49
Remove Emoji in WordPress
/**
* Disable the emoji's
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
@carlosvarela
carlosvarela / .php
Created February 18, 2018 23:08
Remover Stars in Woocommerce
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'my_woocommerce_template_single_rating', 10 );
function my_woocommerce_template_single_rating() {
global $product;
if ( $product->post->comment_status === 'open' )
wc_get_template( 'single-product/rating.php' );
@carlosvarela
carlosvarela / wp-permissions-script
Created November 24, 2017 14:43 — forked from macbleser/wp-permissions-script
WordPress Permissions Configuration Script
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro
#
WP_OWNER=changeme # &lt;-- wordpress owner
WP_GROUP=changeme # &lt;-- wordpress group
WP_ROOT=/home/changeme # &lt;-- wordpress root directory
@carlosvarela
carlosvarela / cpf.php
Created July 5, 2017 20:48 — forked from felipemarcos/wp-cpf-login.php
Permitir login por CPF - WordPress
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Login
*/
class Custom_CPF_Login {