Skip to content

Instantly share code, notes, and snippets.

View clifgriffin's full-sized avatar

Clifton Griffin clifgriffin

View GitHub Profile
@clifgriffin
clifgriffin / add-email-field-for-loggedin-users.php
Last active July 2, 2023 03:07
Add email field back for logged in users for CheckoutWC (Checkout for WooCommerce)
<?php
// Do NOT include opening PHP tag above (<?php)
// Add to:
// - functions.php in child theme
// - Code Snippets
// - Settings > CheckoutWC > Premium Features > PHP Snippets (for Growth and Developer plans)
​add_filter( 'cfw_hide_email_field_for_logged_in_users', '__return_false' );
@clifgriffin
clifgriffin / add-additional-tab.php
Last active May 24, 2023 02:28
Add additional tab to CheckoutWC checkout flow for WooCommerce.
<?php
// Add to functions.php or with your favorite Code Snippets plugin
// Do not include opening PHP tag (<?php)
add_filter( 'cfw_get_checkout_tabs', 'add_age_verification_checkout_step' );
function add_age_verification_checkout_step( $tabs ) {
/**
* Tab Priorities
* - Customer Info: 20
@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 / check-urls.php
Created February 15, 2023 13:32
Check URLs to see if they are on Shopify or WooCommerce
<?php
/**
* Instructions: cd into site directory
*
* Run `wp eval-file ./path/to/script.php`
*/
global $wpdb;
// Query
@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 );
<?php
// Add to functions.php or using the Code Snippets plugin
// Do NOT include opening PHP tag above (<?php)
add_filter(
'woocommerce_default_address_fields',
function( $fields ) {
unset( $fields['postcode']['custom_attributes']['data-parsley-length'] );
$fields['address_1']['custom_attributes']['data-parsley-pattern'] = '/^(?![A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2}).*$/';
$fields['address_1']['custom_attributes']['data-parsley-error-message'] = __( 'Please enter a valid address.', 'your-translation-domain' );
@clifgriffin
clifgriffin / fix-invoice-payment-option.php
Created February 17, 2023 16:29
Fix infinite AJAX refresh when Invoice Payment Option is enabled with CheckoutWC
<?php
add_action(
'wp_enqueue_scripts',
function() {
wp_deregister_script( 'af_ig-front' );
},
20
);
<?php
// Add to functions.php or to CheckoutWC > Advanced > PHP Snippets
// You can also use the Code Snippets plugin
// Do NOT include opening PHP tag above (<?php)
/**
* Set a minimum order amount for checkout
*/
add_action( 'woocommerce_checkout_process', 'wc_prevent_orders_under_minimum' );
add_action( 'woocommerce_before_cart', 'wc_cart_minimum_order_amount' );