Skip to content

Instantly share code, notes, and snippets.

@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@maxrice
maxrice / wc-rename-checkout-coupon-field.php
Last active July 5, 2023 19:34
WooCommerce - rename the "Have a Coupon?" message and "Apply Coupon" field on the checkout
<?php
// rename the "Have a Coupon?" message on the checkout page
function woocommerce_rename_coupon_message_on_checkout() {
return 'Have a Promo Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';
}
add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );
// rename the coupon field on the checkout page
@maxrice
maxrice / wc-rename-cart-coupon-field.php
Created January 21, 2014 23:53
WooCommerce - rename the "Apply Coupon" field on the cart page
<?php
// rename the coupon field on the cart page
function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
@maxrice
maxrice / wc-hide-coupons-cart-checkout.php
Created January 21, 2014 23:43
WooCommerce - hide the coupon form on the cart or checkout page, but leave coupons enabled for use with plugins like Smart Coupons and URL Coupons
<?php
// hide coupon field on cart page
function hide_coupon_field_on_cart( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
@maxrice
maxrice / remove-store-name.php
Created July 6, 2022 21:07
Remove store name from merchant_ref field for First Data Payeezy
<?php
// remove Store name from merchant_ref field for First Data Payeezy
add_filter( 'wc_payment_gateway_first_data_payeezy_credit_card_get_order_base', function( $order ) {
$order->description = sprintf( 'Order #%1$s', $order->get_order_number() );
return $order;
}, 1 );
@maxrice
maxrice / shorten-woo-rest-api-order-payment-method.php
Last active June 23, 2022 18:37
Remove the leading "woocommerce_" from the Woo REST API payment_method attribute
<?php
add_filter( 'woocommerce_rest_prepare_shop_order_object', function( $response ) {
// strip leading woocommerce_ from payment method
if ( ! empty( $response->data['payment_method'] ) ) {
$response->data['payment_method'] = str_replace( 'woocommerce_first_data_', '', $response->data['payment_method'] );
}
return $response;
@maxrice
maxrice / wc-auth-net-cim-save-payment-method-default-checked.php
Created August 3, 2015 16:08
WC Authorize.net CIM: On the payment form, default "securely save to account" checkbox to checked
<?php
// force the "securely save to account" checkbox to default to checked
function wc_auth_net_cim_save_payment_method_default_checked( $html, $form ) {
if ( empty( $html ) || $form->tokenization_forced() ) {
return $html;
}
return str_replace( 'type="checkbox"', 'type="checkbox" checked="checked"', $html );
}
@maxrice
maxrice / wc-auth-net-cim-adjust-auth-only-order-status.php
Last active March 15, 2022 21:59
WooCommerce Authorize.net CIM: Adjust authorize-only transaction order status
<?php
function sv_wc_auth_net_cim_tweak_held_order_status( $order_status, $order, $response ) {
if ( 'on-hold' === $order_status && $response instanceof SV_WC_Payment_Gateway_API_Response && $response->transaction_approved() ) {
$order_status = 'processing';
}
return $order_status;
}
@maxrice
maxrice / wc-hide-flat-rate-shipping.php
Created September 12, 2012 18:04
Hide default flat rate shipping method when free shipping is available
// Hide standard shipping option when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {
@maxrice
maxrice / class-ftp-implicit-ssl-tls.php
Created January 16, 2013 03:11
Basic class to connect to an FTP server with Implicit SSL/TLS and upload a file
<?php
/**
* FTP with Implicit SSL/TLS Class
*
* Simple wrapper for cURL functions to transfer an ASCII file over FTP with implicit SSL/TLS
*
* @category Class
* @author Max Rice
* @since 1.0
*/