Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
ChromeOrange / theme-functions.php
Created July 18, 2012 12:40
woocommerce_get_catalog_ordering_args
add_filter( 'woocommerce_get_catalog_ordering_args','custom_query_sort_args' );
function custom_query_sort_args() {
// Sort by and order
$current_order = ( isset( $_SESSION['orderby'] ) ) ? $_SESSION['orderby'] : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
switch ( $current_order ) {
case 'date' :
$orderby = 'date';
$order = 'desc';
@ChromeOrange
ChromeOrange / gist:e5950c3517516bd9a90362d4fbc906b8
Created February 9, 2022 15:20
add_filter( 'woocommerce_sagepay_direct_data', 'telephone_order_payment', 10, 2 );
add_filter( 'woocommerce_sagepay_direct_data', 'telephone_order_payment', 10, 2 );
function telephone_order_payment( $data, $order ) {
$order_id = $order->get_id();
$type = get_post_meta( $order_id, '_created_via', TRUE);
if ( $type !== 'checkout' ) {
$data['AccountType'] = 'M';
}
@ChromeOrange
ChromeOrange / functions.php
Created July 29, 2012 22:32
Replace all add to cart button text
<?php
// Single Product
add_filter( 'single_add_to_cart_text', 'custom_single_add_to_cart_text' );
function custom_single_add_to_cart_text() {
return 'Add to cart'; // Change this to change the text on the Single Product Add to cart button.
}
// Variable Product
add_filter( 'variable_add_to_cart_text', 'custom_variable_add_to_cart_text' );
@ChromeOrange
ChromeOrange / gist:10013862
Last active December 16, 2022 18:24
Sort shipping methods by cost in WooCommerce 2.1. Add to theme functions.php file
/**
* Sort WooCommerce shipping methods by cost, lowest to highest
*/
add_filter( 'woocommerce_package_rates' , 'sort_woocommerce_available_shipping_methods', 10, 2 );
function sort_woocommerce_available_shipping_methods( $rates, $package ) {
if ( !$rates ) return $rates;
$tmp = Array();
foreach( $rates as $ma ) {
@ChromeOrange
ChromeOrange / gist:5778923
Created June 14, 2013 01:59
Remove postcode requirement if billing or shipping country is Ireland
/**
* Remove postcode requirement if billing or shipping country is Ireland
* Add to your theme functions.php file
*/
add_action( 'woocommerce_checkout_process', 'custom_country_check' );
function custom_country_check(){
global $woocommerce;
@ChromeOrange
ChromeOrange / gist:6548750
Last active February 28, 2022 11:18
Modifying Headers in WooCommerce PDF Invoice
/**
* Modifying Headers
*
* Add to your theme functions.php
*/
add_filter( 'pdf_template_table_headings','custom_pdf_template_table_headings' );
function custom_pdf_template_table_headings( $headers ) {
$headers = '<table class="shop_table orderdetails" width="100%">' .
'<thead>' .
'<tr><th colspan="7" align="left"><h2>' . esc_html__('Order Details', PDFLANGUAGE) . '</h2></th></tr>' .
@ChromeOrange
ChromeOrange / gist:9200450
Last active November 30, 2021 10:40
Add a surcharge if certain products are in the cart, ideal for setup fees etc
/**
* Add a fixed surcharge to your cart / checkout based on products in cart
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*
* Change $fixed to set the surcharge to a value to suit
*
* Change in_array to !in_array to EXCLUDE the $countries array from surcharges
*
* Uses the WooCommerce fees API
* Add to theme functions.php
@ChromeOrange
ChromeOrange / resultY.html
Last active April 15, 2021 16:06
resultY.html for sites not using pretty permalinks
<html>
<head>
<meta http-equiv='Refresh' content='2; Url="<WPDISPLAY ITEM=MC_callback>&MC_order=<WPDISPLAY ITEM=MC_order>&transId=<WPDISPLAY ITEM=transId>&transStatus=<WPDISPLAY ITEM=transStatus>&transTime=<WPDISPLAY ITEM=transTime>&authAmount=<WPDISPLAY ITEM=authAmount>&authCurrency=<WPDISPLAY ITEM=authCurrency>&rawAuthMessage=<WPDISPLAY ITEM=rawAuthMessage>&rawAuthCode=<WPDISPLAY ITEM=rawAuthCode>&callbackPW=<WPDISPLAY ITEM=callbackPW>&cardType=<WPDISPLAY ITEM=cardType>&countryMatch=<WPDISPLAY ITEM=countryMatch>&AVS=<WPDISPLAY ITEM=AVS>&MC_transactionNumber=<WPDISPLAY ITEM=MC_transactionNumber>&futurePayId=<WPDISPLAY ITEM=futurePayId>&futurePayStatusChange<WPDISPLAY ITEM=futurePayStatusChange>"'>
<title>Payment Successful</title>
</head>
<h1>Payment Successful</h1>
<a href="<WPDISPLAY ITEM=MC_callback>&MC_order=<WPDISPLAY ITEM=MC_order>&transId=<WPDISPLAY ITEM=transId>&transStatus=<WPDISPLAY ITEM=transStatus>&transTime=<WPDISPLAY ITEM=transTime>&authAmount=<WPDISPLAY ITEM=authAmount>&authCurrency=<WPDISP
@ChromeOrange
ChromeOrange / functions.php
Created August 31, 2012 12:20
Change Single Product Tab Titles and Headings
<?php
/**
* Tab Title filters do not work with WooCommerce 1.6.5.1 or lower
* Please download this zip file http://cl.ly/2Y3S3D3M3C23 , extract the 3 files and copy them to :
* wp-content/themes/YOUR_THEME/woocommerce/single-product/tabs/
**/
add_filter ( 'woocommerce_product_description_tab_title', 'custom_product_description_tab_title' ) ;
function custom_product_description_tab_title() {
@ChromeOrange
ChromeOrange / gist:56ce4571836429af330d
Created October 12, 2014 14:54
Set a maximum shipping cost for WooCommerce, add this to functions.php - works with all shipping methods
/**
* Set maximum shipping cost in WooCommerce
*/
add_filter( 'woocommerce_package_rates' , 'woocommerce_set_maximum_shipping_cost', 10, 2 );
function woocommerce_set_maximum_shipping_cost( $rates, $package ) {
foreach( $rates as $rate ) {
// Change 10 to your maximum shipping cost
if( $rate->cost > 10 ) {
$rate->cost = 10;