Skip to content

Instantly share code, notes, and snippets.

View xlplugins's full-sized avatar

XLPlugins xlplugins

View GitHub Profile
@xlplugins
xlplugins / 2nd Radio button selected on page load
Created April 21, 2025 08:11
2nd Radio button selected on page load
add_filter( 'woocommerce_available_payment_gateways', 'set_default_payment_gateway' );
function set_default_payment_gateway( $available_gateways ) {
// Ensure there are available payment gateways
if ( ! is_admin() && isset( $available_gateways ) && count( $available_gateways ) > 1 ) {
// Get the keys of available gateways
$gateway_keys = array_keys( $available_gateways );
// Set the second gateway (index 1) as default
if ( isset( $gateway_keys[1] ) ) {
@xlplugins
xlplugins / Upsell Addon for add mutiple order product to upsell with predefined discount set in upsell offer
Last active April 16, 2025 15:12
Upsell Addon for add mutiple order product to upsell with predefined discount set in upsell offer
class WFOCU_Upsell_Addon {
public function __construct() {
add_action( 'wp_footer', [ $this, 'js' ] );
add_shortcode( 'wfocu_bucket_total', [ $this, 'bucket_total' ] );
add_filter( 'wfocu_build_offer_product_before', array( $this, 'maybe_check_offer_data_for_qty_change' ), 10, 2 );
add_filter( 'wfocu_prepare_upsell_package_before', array( $this, 'maybe_check_offer_data_for_qty_change' ), 10, 2 );
add_action( 'wfocu_add_custom_html_above_accept_button', array( $this, 'schemes_template_html' ), 10, 2 );
add_filter( 'wfocu_validate_charge_request', '__return_true' );
}
@xlplugins
xlplugins / clone item as bump product at checkout
Last active April 16, 2025 07:56
clone item as bump product at checkout
/**
* WFOB_Bump_Addons - Optimized class for managing order bumps with WooCommerce cart items
*/
class WFOB_Bump_Addons {
/**
* @var array Filtered order bumps
*/
private $filtered_bumps = [];
@xlplugins
xlplugins / gist:6c76875a42641c6e990eb44ae7d81831
Last active April 14, 2025 08:32
Funnelkit Checkout Dequeue Theme Assets by using Handler
class WFACP_Dequeue_Theme_Asset_by_Slug {
/**
* Array of asset handles that should be dequeued if they exist
* These will be checked against both JS and CSS registrations
*/
private $assets_to_dequeue = [
'bootstrap',
'select2',
@xlplugins
xlplugins / gist:361ce7ca3f0328903fffad32686dfe96
Last active April 14, 2025 07:27
Funnelkit Checkout: WooCommerce Conditional Checkout Fields Based on Product Type and Payment Method
class WFACP_Conditional_field_Based_On_Payment_Method {
// Payment method that requires address fields
public $address_required_payment = 'mollie_wc_gateway_klarna';
// Minimal fields that will always be shown
public $minimal_fields = [
'billing_email',
'billing_first_name',
'billing_last_name',
@xlplugins
xlplugins / update_order_meta_on_failure.php
Last active April 14, 2025 11:27
Update order meta based on order note for stripe failures & remove when order moved to completed stasuses
/** * Add a note to the order when the order status changes to failed
*
* @param int $order_id The ID of the order.
* @param WC_Order $order The order object.
* @param array $status_transition The status transition data.
*/
add_action( 'woocommerce_order_status_failed', function ( $order_id, $order, $status_transition ) {
if ( $order->get_payment_method() !== 'fkwcs_stripe' ) {
return;
}
@xlplugins
xlplugins / exclude CARD.js from defer in SiteGround optimizer
Created April 9, 2025 08:01
exclude CARD.js from defer in SiteGround optimizer
add_filter( 'sgo_js_async_exclude', function ( $exclude_list ) {
$exclude_list[] = 'jCard_js';
return $exclude_list;
} );
@xlplugins
xlplugins / gist:6af25d77540d35d88a5515bd31c9f1b0
Created April 8, 2025 13:26
Funnelkit Cart: Update Quanitity count when add or update in the cart item
class FunnelKitCartJsCookie_Quantity {
public function __construct() {
add_action( 'wp_head', [ $this, 'js' ] );
add_filter( 'fkcart_re_run_slide_cart', '__return_true' );
add_filter( 'fkcart_fragments', [ $this, 'send_fragments' ] );
}
public function send_fragments( $fragments ) {
$instance = FKCart\Includes\Front::get_instance();
$fragments['fkcart_qty'] = $instance->get_cart_content_count();
@xlplugins
xlplugins / amazon-pay
Created April 8, 2025 11:44
amazon-pay
add_action( 'woocommerce_after_checkout_form', function () {
echo '<div id="classic_pay_with_amazon"></div>';
} );
add_action( 'wp_footer', function () {
?>
<script>
(function ($) {
@xlplugins
xlplugins / gist:0c9ed7f98299bf5d0b2d0551f6196cd6
Created April 8, 2025 07:35
Funnelkit Checkout: Radio button conditional field
class WFACP_Conditional_field_tmp {
private $conditional_field = [];
public function __construct() {
/* Conditional fields */
$this->conditional_field = [
'tax_exempt_yn' => [ /* tax_exempt_yn*/