Skip to content

Instantly share code, notes, and snippets.

View BFTrick's full-sized avatar

Patrick Rauland BFTrick

View GitHub Profile
@BFTrick
BFTrick / price.php
Created May 11, 2016 19:13
WooCommerce Price Template
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<p class="price"><?php echo $product->get_price_html(); ?></p>
<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>
@BFTrick
BFTrick / functions.php
Last active August 7, 2017 08:53
Change WooCommerce Email Styles
<?php
add_filter( 'woocommerce_email_styles', 'patricks_woocommerce_email_styles' );
function patricks_woocommerce_email_styles( $css ) {
$css .= "#template_header { background-color: #231f20; }";
return $css;
}
@BFTrick
BFTrick / functions.php
Created May 6, 2016 21:12
Add a call to order button to the single product page
<?php
function patricks_woocommerce_call_to_order_text() {
echo '<p>Call to order this product. <strong>123-456-7890</strong>.</p>';
}
add_action('woocommerce_single_product_summary','patricks_woocommerce_call_to_order_text', 30);
@BFTrick
BFTrick / functions.php
Last active October 29, 2019 19:12
Add a Call to order button on the product archive page(s) (Shop page)
<?php
function patricks_woocommerce_call_to_order_button(){
global $product; //get the product object
if ( $product ) { // if there's a product proceed
$url = esc_url( $product->get_permalink() ); //get the permalink to the product
echo '<a rel="nofollow" href="' . $url . '" class="button add_to_cart_button ">Call to order!</a>'; //display a button that goes to the product page
}
}
add_action('woocommerce_after_shop_loop_item','patricks_woocommerce_call_to_order_button', 10);
@BFTrick
BFTrick / functions.php
Created May 6, 2016 21:05
Remove Add to Cart Buttons
<?php
function patricks_remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); // removes the add to cart button on the shop page
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); //removes the add to cart button on the single product page
}
add_action('init','patricks_remove_loop_button');
@BFTrick
BFTrick / style.css
Created May 5, 2016 22:02
Style WooCommerce Add to Cart Buttons
.single-product .product .single_add_to_cart_button.button{
background-color: #333333;
color: #FFFFFF;
}
.woocommerce .product .add_to_cart_button.button{
background-color: #333333;
color: #FFFFFF;
}
@BFTrick
BFTrick / functions.php
Created March 22, 2016 22:17
Disable Plugin Updates
// PLEASE DON'T USE THIS. I save this an example of what *not* to do.
remove_action( 'admin_notices', 'woothemes_updater_notice' );
//Disable plugins updates
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
@BFTrick
BFTrick / optin-monster-load-on-tag.php
Last active August 29, 2015 14:18
Load OptinMonster Opt-ins based on the post tag.
<?php
/*
* Plugin Name: OptinMonster Load on Tag
* Plugin URI: https://gist.github.com/BFTrick/bc0dab3881660645aaf6
* Description: Load OptinMonster Opt-ins based on the post tag.
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com
* Version: 1.0
*/
<?php
add_filter( 'registered_post_type', 'my_portfolio_cpt', 20, 2 );
function my_portfolio_cpt( $post_type, $args ) {
if ( 'portfolio-item' == $post_type ) {
global $wp_post_types;
$args->rewrite->slug = __( 'resources', 'my_theme_textdomain' );
$wp_post_types[ $post_type ] = $args;
}
}
@BFTrick
BFTrick / woocommerce-enable-free-shipping-per-product.php
Last active October 29, 2019 19:11
Enable Free Shipping on a per product basis in WooCommerce.
<?php
/**
* Plugin Name: WooCommerce Enable Free Shipping on a Per Product Basis
* Plugin URI: https://gist.github.com/BFTrick/d4a21524a8f7b25ec296
* Description: Enable free shipping for certain products
* Author: Patrick Rauland & eugenf
* Author URI: http://speakinginbytes.com/
* Version: 1.0.2
*
* This program is free software: you can redistribute it and/or modify