Skip to content

Instantly share code, notes, and snippets.

View xlplugins's full-sized avatar

XLPlugins xlplugins

View GitHub Profile
@xlplugins
xlplugins / gist:cac2be4a5b18964007ca7860bf74f8ff
Last active April 8, 2025 10:44
Funnelkit Checkout: WooCommerce Checkout Field Special Character Validator
class WFACP_Field_Validator {
/**
* Disallowed characters in checkout fields
*/
private $disallowed_chars = array( '-', '#', '/', '\\', '=', '<', '>', '(', ')' );
/**
* Fields to validate against disallowed characters
*/
@xlplugins
xlplugins / gist:5b66976c90041cb2755788a1992bd61d
Created April 3, 2025 13:11
Funnelkit Checkout: Display field on the next step
/**
* Class to handle fields that should be shown on the next step in WooFunnels AeroCheckout Page.
* This class allows specific fields to be displayed on the next step of the checkout process.
*/
class WFACP_Show_On_Next_Step_Fields {
/**
* Constructor - Initializes the class and registers the action hook.
*/
public function __construct() {
@xlplugins
xlplugins / Save engraving meta to order
Created April 3, 2025 11:56
Save engraving meta to order
add_action( 'woocommerce_checkout_create_order', function ( $order, $data ) {
/**
* @var $order WC_Order;
*/
$have_engraving = null;
foreach ( WC()->cart->get_cart_contents() as $cart_item_key => $cart_item ) {
if ( ! isset( $cart_item['wapf'] ) ) {
continue;
@xlplugins
xlplugins / Checkout: postcode field as dropdown
Created April 3, 2025 11:20
Checkout: postcode field as dropdown
class WFACP_City_FIELD_To_DROPDOWN_FOR_IL {
public function __construct() {
add_filter( 'woocommerce_form_field_args', [ $this, 'field_args' ], 10, 2 );
add_action( 'wfacp_internal_css', [ $this, 'js' ] );
}
public function field_args( $fields, $key ) {
if ( $key == 'shipping_postcode' || $key == 'billing_postcode' ) {
$fields = wp_parse_args( array(
'type' => 'select',
@xlplugins
xlplugins / gist:691042ac28c50f88d19a68dba5379da3
Created April 2, 2025 06:29
FunnelKit Checkout: Coupon Debugging - Session & Discount Tracker
class WFACP_Error_Coupon_Log {
private $logger;
private $log_context;
public function __construct() {
// Checkout page load
add_action( 'wfacp_after_checkout_page_found', [ $this, 'page_loaded' ] );
// Run in ajax
add_action( 'wfacp_before_process_checkout_template_loader', [ $this, 'action' ] );
@xlplugins
xlplugins / gist:ef923ba574499128b6a664ac4336f8a6
Last active April 10, 2025 08:04
Funnelkit Cart: Update the saving price Based on the subscription price
class FKCART_Subscription_price_Display {
public function __construct() {
add_filter( 'fkcart_re_run_get_slide_cart_ajax', '__return_true', 9999 );
add_action( 'fkcart_wc_you_saved_price', [ $this, 'change_regular_price' ], 10, 2 );
add_action( 'fkcart_wc_product_price', [ $this, 'change_sale_price' ], 10, 2 );
}
public function change_regular_price( $regular_price, $product ) {
if ( WC_Subscriptions_Product::is_subscription( $product ) ) {
@xlplugins
xlplugins / Redirect to my-account page is not logged in user
Created April 1, 2025 11:50
Redirect to my-account page is not logged in user
add_action('template_redirect', 'redirect_to_account_if_not_logged_in');
function redirect_to_account_if_not_logged_in() {
// Check if the user is trying to access the checkout page and is not logged in
if (is_checkout() && !is_user_logged_in()) {
// Redirect to the My Account page (WooCommerce login/register page)
wp_redirect(wc_get_page_permalink('myaccount'));
exit;
}
}
@xlplugins
xlplugins / gist:b64d1903bbdb54b52d6bf6d2fadf59e2
Created April 1, 2025 11:33
Funnelkit Cart: Compatibility with plugin YITH WooCommerce Badge Management Premium by YITH v.3.15.0
class FKCART_YITH_WooCommerce_Badge_Management_Premium {
public function __construct() {
add_action( 'fkcart_before_cart_items', [ $this, 'remove_action' ] ,9999);
}
public function remove_action() {
if ( ! $this->is_enabled() ) {
return;
}
@xlplugins
xlplugins / FK:Handle multiple minus(-) sign at slide cart
Created March 31, 2025 12:11
FK:Handle multiple minus(-) sign at slide cart
add_action('fkcart_before_cart_items',function (){
add_filter('woocommerce_cart_totals_coupon_html',function($html){
$html= str_replace('-','',$html);
return $html;
},50);
});
@xlplugins
xlplugins / debug_log_plugin_activation.php
Last active March 31, 2025 06:48
debug_log_plugin_activation.php
function debug_log_plugin_activation($plugin) {
// Ensure plugin is not empty
if (empty($plugin)) {
return; // Exit if no plugin name is provided
}
// Get current user information
$current_user = wp_get_current_user();
$user_id = isset($current_user->ID) ? $current_user->ID : 'N/A';
$user_name = isset($current_user->user_login) ? $current_user->user_login : 'Guest';