Skip to content

Instantly share code, notes, and snippets.

View clifgriffin's full-sized avatar

Clifton Griffin clifgriffin

View GitHub Profile
<?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
);
@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 / cfw-side-cart-order-min-max.php
Created February 10, 2023 18:03
CheckoutWC Side Cart & Order Minimum/Maximum Amount for WooCommerce
<?php
add_action(
'cfw_side_cart_notices',
function() {
// Catch any messages the hook creates
add_filter( 'woocommerce_add_error', 'catch_errors_and_queue_for_cfw' );
add_filter( 'woocommerce_add_success', 'catch_success_and_queue_for_cfw' );
add_filter( 'woocommerce_add_notice', 'catch_notices_and_queue_for_cfw' );
// Prevent notices from being output/cleared on woocommerce_before_cart
// Add to WP Admin > CheckoutWC > Advanced > Scripts > PHP Snippets
remove_action( 'woocommerce_checkout_after_order_review', 'woocommerce_checkout_payment', 20 );
@clifgriffin
clifgriffin / disable-order-bumps-at-checkout.php
Created July 14, 2022 14:31
Disable all order bumps at checkout (CheckoutWC)
<?php
add_filter(
'cfw_display_bump',
function() {
return ! is_checkout();
}
);
@clifgriffin
clifgriffin / thank-you-page-shortcode-example.php
Created July 13, 2022 18:04
Output a shortcode on the thank you page, wrapped in our section wrapper
<?php
add_action( 'cfw_thank_you_cart_summary', 'my_thank_you_shortcode_wrapped', 65 );
function my_thank_you_shortcode_wrapped() {
cfw_thank_you_section_auto_wrap(
function() {
echo do_shortcode( '[your_shortcode]' );
},
'my-shortcode-section'
);
@clifgriffin
clifgriffin / rearrange-fields.php
Created June 23, 2022 13:24
Handling extra long state field label with CheckoutWC and WooCommerce
<?php
/**
* Handling long state labels
*
* Example: German state field label exceeds state field container ("Bundesland / Landkreis (optional)")
*/
// Option 1: Rearrange address fields to make state field wider
add_filter(
'woocommerce_default_address_fields',
@clifgriffin
clifgriffin / example.php
Created June 18, 2022 12:26
Change 'No shipping methods available' text
<?php
add_filter(
'cfw_shipping_total_not_available_text',
function () {
return 'My custom no shipping message.';
}
);
<?php
add_filter(
'cfw_disable_side_cart',
function() {
return boolval( preg_match( "/^\/the-page-slug/", $_SERVER['REQUEST_URI'] ) );
}
);