Skip to content

Instantly share code, notes, and snippets.

@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 / gist:2de923beb26fe6a1d0c560af1b267032
Created April 8, 2020 16:21
Add transaction ID to PDF Invoices payment method
add_filter( 'pdf_invoice_payment_method_title', 'custom_pdf_invoice_payment_method_title', 10, 2 );
function custom_pdf_invoice_payment_method_title( $payment_method_title, $order_id ) {
$transaction_id = get_post_meta( $order_id, '_transaction_id', TRUE );
if( isset( $transaction_id ) && $transaction_id != '' ) {
$payment_method_title .= "<br />(" . $transaction_id . ")";
}
return $payment_method_title;
@ChromeOrange
ChromeOrange / gist:0853adfb17f8c0e02a58ee8eb0d5fbaf
Created October 25, 2019 14:18
Add button to clear the WooCommerce logs in System Status -> Tools
// Add to your custom functions
// Uses apply_filters( 'woocommerce_debug_tools', $tools )
add_filter( 'woocommerce_debug_tools', 'woocommerce_debug_tools_remove_logs' );
function woocommerce_debug_tools_remove_logs( $tools ) {
// Disbale Remove Logs button
$disable_remove_logs = apply_filters( 'woocommerce_disable_woocommerce_debug_tools_remove_logs', FALSE );
if( !$disable_remove_logs ) {
@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 / gist:914348c0e16cbf9b891b3a1ee2369789
Created June 3, 2018 12:15
Add product description to item name
add_filter( 'pdf_invoice_item_name', 'add_product_description_pdf_invoice_item_name', 10, 4 );
function add_product_description_pdf_invoice_item_name( $item_name, $item, $product, $order ) {
// Use $product->get_id() if you want to get the post id for the product.
$item_name .= '<p>' . $product->get_description() . '</p>';
return $item_name;
}
'attributes' => array(
array(
'name' => 'Brand',
'slug' => 'pa_brand',
'options' => array(
'Kravet Basics'
),
'visible' => true
)
)
@ChromeOrange
ChromeOrange / gist:7b89e9cab49cfd82543e
Created May 6, 2015 18:32
custom_woocommerce_email_order_meta
add_action('woocommerce_email_order_meta', 'custom_woocommerce_email_order_meta', 10,3 );
function custom_woocommerce_email_order_meta ( $order, $sent_to_admin, $plain_text ) {
wp_mail( 'YOUR_EMAIL_ADDRESS', 'woocommerce_email_order_meta ' . time(), '<pre>' . print_r( $order, TRUE ) . '</pre>' );
}
@ChromeOrange
ChromeOrange / gist:b30ba62eac9edb416b14
Created April 9, 2015 03:45
Fix PayPal Rounding Issues. Add to theme functions.php file
add_filter( 'woocommerce_paypal_args', 'fix_paypal_rounding_errors', 10, 2 );
function fix_paypal_rounding_errors ( $paypal_args = NULL, $order = NULL ) {
if( $paypal_args ) {
foreach( $paypal_args as $key => $value ) {
if( substr( $key, 0, 7 ) == 'amount_' || substr( $key, 0 , 9 ) == 'shipping_' ) {
$paypal_args[$key] = number_format( round($value,2), 2, '.', '' );
@ChromeOrange
ChromeOrange / gist:161978603b316fbbb195
Created March 6, 2015 13:06
Get the XML for WooCommerce FedEx shipping
if ( $this->debug ) {
echo "REQUEST:\n" .'<pre>' . htmlentities( str_replace( "><", ">\r\n<", $client->__getLastRequest()) ). '</pre>' . "\n";
echo "RESPONSE:\n" .'<pre>' . htmlentities( str_replace( "><", ">\r\n<", $client->__getLastResponse()) ). '</pre>' . "\n";
}
@ChromeOrange
ChromeOrange / gist:33af495f6afdd5d7a397
Created February 3, 2015 11:41
Set a minimum order amount in WooCommerce and disable checkout page if it is not met
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
if ( WC()->cart->total < $minimum ) {
WC()->add_error( sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
woocommerce_price( $minimum ),