Skip to content

Instantly share code, notes, and snippets.

View clifgriffin's full-sized avatar

Clifton Griffin clifgriffin

View GitHub Profile
@clifgriffin
clifgriffin / show-shipping-method-in-totals.php
Last active April 3, 2024 14:59
Show shipping method in CheckoutWC totals table.
<?php
// Do NOT include opening PHP tag above (<?php)
add_filter( 'cfw_cart_totals_shipping_label', function( $label ) {
$chosen_shipping_methods_labels = array();
$packages = WC()->shipping->get_packages();
foreach ( $packages as $i => $package ) {
$chosen_method = WC()->session->get( 'chosen_shipping_methods' )[ $i ] ?? false;
@clifgriffin
clifgriffin / custom-header.php
Last active March 12, 2024 16:51
A simple example of how to add a custom header to Checkout for WooCommerce.
<?php
// Do NOT include the opening php tag.
// Place in your theme's functions.php file
add_action( 'cfw_custom_header', function() {
?>
<!-- Some custom CSS for your new header -->
<style type="text/css">
nav a {
font-weight: bold;
@clifgriffin
clifgriffin / exclude-terms-and-condtiions-from-field-persistence-service.php
Created March 23, 2023 14:07
Prevent terms and conditions checkbox from being locally cached on CheckoutWC checkout page.
<?php
add_filter( 'cfw_field_data_persistence_excludes', function( $excludes ) {
$excludes[] = '#terms';
return $excludes;
} );
@clifgriffin
clifgriffin / hide-shipping-from-delivery-methods-basesd-on-product-category.php In CheckoutWC's Delivery method, hide the Shipping option completely when at least one product in the cart is assigned to a specific category.
<?php
/*
* In CheckoutWC's Delivery method, hide the Shipping option completely when at least
* one product in the cart is assigned to a specific category.
*
* @author Obi Juan <hola@obijuan.dev>
* @link https://obijuan.dev
*/
/*
@clifgriffin
clifgriffin / enable-tracking-without-emails.php
Created March 4, 2024 15:08
CheckoutWC: Enable Abandoned Cart Recovery tracking without emails.
<?php
/**
* Enable ACR cart tracking without published emails
*
* Add to your child theme's functions.php file or to WP Admin > CheckoutWC > Advanced > Scripts > PHP Snippets
* Do NOT include the opening PHP tag above (<?php)
*/
add_filter( 'cfw_acr_track_cart_without_emails', '__return_true' );
@clifgriffin
clifgriffin / set-username-to-email.php
Last active November 13, 2023 06:00
Force WooCommerce to use email address as username when registering new accounts.
<?php
// Do NOT include the opening php tag.
// Place in your theme's functions.php file
add_filter( 'woocommerce_new_customer_data', function( $data ) {
$data['user_login'] = $data['user_email'];
return $data;
} );
@clifgriffin
clifgriffin / example.php
Last active October 10, 2023 20:40
Remove billing address fields for digital orders in Checkout for WooCommerce
<?php
// Do NOT include the opening php tag.
// Place in your theme's functions.php file
add_filter( 'cfw_get_billing_checkout_fields', 'remove_checkout_fields', 100 );
function remove_checkout_fields( $fields ) {
unset( $fields['billing_company'] );
unset( $fields['billing_city'] );
unset( $fields['billing_postcode'] );
@clifgriffin
clifgriffin / ab-testing-example.php
Last active August 28, 2023 14:57
CheckoutWC AB testing example
<?php
/**
* The following code MUST be deployed in an MU plugin to work
*/
add_action( 'cfw_init_ab_tests', function() {
cfw_register_ab_test( 'cfw_disabled', 'example_set_cfw_disabled' );
// To enable the test progamatically, you would use this call:
cfw_activate_ab_test( 'cfw_disabled' );
@clifgriffin
clifgriffin / output-custom-html.php
Created August 23, 2023 15:23
Output custom HTML anywhere on the CheckoutWC WooCommerce checkout page.
<?php
/**
* Output custom HTML below the CheckoutWC cart summary
*/
add_action( 'cfw_after_cart_summary', function() {
?>
<div class="example-container-class">
<h2>A heading!</h2>
<p>A paragraph tag.</p>
<p>A paragraph tag with inline PHP: <?php echo 'Inline PHP!'; ?></p>
@clifgriffin
clifgriffin / disable-express-checkout.php
Created July 26, 2023 19:26
Disable CheckoutWC express checkout buttons when autoship is active
<?php
add_action( 'cfw_checkout_customer_info_tab', function () {
if ( function_exists( 'autoship_cart_has_valid_autoship_items' ) && autoship_cart_has_valid_autoship_items() ) {
remove_action( 'cfw_checkout_customer_info_tab', 'cfw_payment_request_buttons', 10 );
}
}, 0 );