Skip to content

Instantly share code, notes, and snippets.

View clifgriffin's full-sized avatar

Clifton Griffin clifgriffin

View GitHub Profile
@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 / 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 / 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 / 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 / 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 );
@clifgriffin
clifgriffin / hide-country-field.php
Created May 22, 2023 15:15
How to hide the country field with CheckoutWC
<?php
add_filter( 'woocommerce_default_address_fields', 'custom_override_default_address_fields', 100000 + 100 );
function custom_override_default_address_fields( $fields ) {
$fields['country']['class'] = array( 'cfw-force-hidden' );
$fields['country']['columns'] = 0;
$fields['postcode']['columns'] = 6;
$fields['state']['columns'] = 6;
return $fields;
<?php
add_filter( 'cfw_display_bump', function( $display_bump ) {
if ( ! class_exists( '\\WC_Subscriptions_Cart' ) ) {
return $display_bump;
}
if ( \WC_Subscriptions_Cart::cart_contains_subscription() ) {
return false;
}
<?php
function custom_output_pickup_instructions( \WC_Order $order ) {
$location = $order->get_meta( '_cfw_pickup_location', true );
if ( empty( $location ) ) {
return;
}
$raw_address = get_post_meta( $location, 'cfw_pl_address', true );
@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 / custom-text-payment-page.php
Created March 22, 2023 18:17
Adding custom HTML to the CheckoutWC Payment step
<?php
// 2 - Above Mobile Coupons
// 7 - Above Payment Methods
// 15 - Above Billing Address Group
// 27 - Above Order Notes Field
// 35 - Above Terms and Conditions
add_action( 'cfw_checkout_payment_method_tab', function() {
echo '<h2>'Your Disclaimer and Other HTML</h2>';
}, 2 );