Skip to content

Instantly share code, notes, and snippets.

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 / actions-custom-output.php
Last active November 27, 2016 19:29
Custom color calculator based on the selected background color
<?php
/**
* Actions.
*
* This file adds the required CSS to the front end to the Actions Pro Theme.
*
* @package Actions
* @author WPDevHQ
* @license GPL-2.0+
* @link http://www.wpdevhq.com/
@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;
}
}
@WPDevHQ
WPDevHQ / custom-cpt-slider.php
Last active August 31, 2016 17:15
Generate a bxSlider from a Custom Post Type
<div class="bx-wrapper">
<ul class="bxslider">
<?php
$slider = new WP_Query(array( 'post_type' => 'homepage_slider' ) );
if( $slider->have_posts() ) :
while($slider->have_posts()) :
$slider->the_post();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?>
<li class="featured-image" style="background-image: url('<?php echo $thumb['0'];?>')">
@WPDevHQ
WPDevHQ / font-awesome.php
Created August 23, 2016 11:27 — forked from justintadlock/font-awesome.php
PHP array of Font Awesome icons.
<?php
// Font Awesome v. 4.6.
function jt_get_font_icons() {
return array(
'fa-glass' => 'f000',
'fa-music' => 'f001',
'fa-search' => 'f002',
'fa-envelope-o' => 'f003',