Skip to content

Instantly share code, notes, and snippets.

<?php
add_action('wp_head', 'webworks_facebook_analytics');
function webworks_facebook_analytics() {
if(current_user_can('manage_options')) {
return;
}
?>
@WPDevHQ
WPDevHQ / Contract Killer 3.md
Created March 19, 2017 14:12
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

/**
* Redirect to a specific page when clicking on Continue Shopping in the single product page
*
* @return void
*/
function wc_custom_redirect_continue_shopping( $message ) {
if ( strpos( $message, __( 'View Cart', 'woocommerce' ) ) !== false ) {
$message = str_replace( esc_url( wc_get_page_permalink( 'cart' ) ), esc_url( wc_get_page_permalink( 'shop' ) ), $message );
$message = str_replace( __( 'View Cart', 'woocommerce' ), esc_html__( 'Continue Shopping', 'woocommerce' ), $message );
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
add_action( 'woocommerce_proceed_to_checkout', 'change_url_to_checkout', 20 );
function change_url_to_checkout() {
$cart = WC()->cart->get_cart();
$url = '';
foreach ( $cart as $item ) {
if ( $item['product_id'] === 70 ) {
$url = 'put_your_extra_page_url_here';
break;
@WPDevHQ
WPDevHQ / style.css
Created December 31, 2016 00:18
On single product page, default WooCommerce css use equal width for product image (left) and product summary (right). In a custom project, sometimes you want to make product summary width bigger, for example 73% for your product summary and 23% for your product image. You only need to put this CSS code to the bottom of style.css file in your chi…
/**
* single product page layout *
* 23% (image) + 4% (spacing) + 73% (summary) = 100% *
**/
/* modify product image width */
.woocommerce div.product div.images, .woocommerce #content div.product div.images, .woocommerce-page div.product div.images, .woocommerce-page #content div.product div.images {
width: 23%;
}
/* modify product summary width */
.woocommerce div.product div.summary, .woocommerce #content div.product div.summary, .woocommerce-page div.product div.summary, .woocommerce-page #content div.product div.summary {
// Add to a js file in your theme/child theme or create a new js file. If you create a new file, remember to enqueue from functions.php. See example below.
// Adds thumbnail hover to main product img
jQuery(document).ready(function($) {
// Get the main WC image as a variable
var wcih_main_imgage = $( 'a.woocommerce-main-image' ).attr( 'href' );
// This is what will happen when you hover a product thumb
$(".thumbnails a").hover(
// Swap out the main image with the thumb
function(){
// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' );
get_option( 'woocommerce_cart_page_id' );
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' );
get_option( 'woocommerce_thanks_page_id' );
get_option( 'woocommerce_myaccount_page_id' );
get_option( 'woocommerce_edit_address_page_id' );
get_option( 'woocommerce_view_order_page_id' );
get_option( 'woocommerce_terms_page_id' );
@WPDevHQ
WPDevHQ / perfect_excerpt.php
Created December 7, 2016 17:32
Perfect Excerpts for WordPress
// if you're tired of excerpts cutting in half, here it is, the perfect solution
// that shortens your excerpt to full sentences in your characters limit.
<?php
function perfect_excerpt( $length ) {
$excerpt = get_the_excerpt($post->ID);
$short_excerpt = substr($excerpt, 0, $length);
// look for the last period
$finishline = strrpos( $short_excerpt, '.');
@WPDevHQ
WPDevHQ / iaf-plugin.php
Created October 8, 2016 12:40 — forked from nickdgreen/iaf-plugin.php
liveEstimatePHPCode.php creates a form to collect inputs from a client and then calculates the estimated courier charge based on the type of vehicle and the distance using UK post codes. iaf-plugin.php appears to create a widget (i.e. it appears in the widget menu) but when added to a page nothing is dispalyed.
<form action="#formend" method="post"><input name="submited" type="hidden" value="true" />
<table border="0" width="450px">
<tbody>
<tr>
<td width="200px">Collection Postcode:</td>
<td width="250px"><input name="fromCode" size="10" type="text" value="" /></td>
</tr>
<tr>
<td>Destination Postcode:</td>
<td><input name="toCode" size="10" type="text" value="" /></td>
@WPDevHQ
WPDevHQ / foreach
Created September 2, 2016 11:19 — forked from dsgnr/foreach
foreach (dirname((__FILE__)) as $filename) {
$path = plugin_dir_pathdirname(dirname(__FILE__)) . 'includes/partials/' . $filename;
if (is_file($path)) {
require $path;
}
}