Skip to content

Instantly share code, notes, and snippets.

View xlplugins's full-sized avatar

XLPlugins xlplugins

View GitHub Profile
@xlplugins
xlplugins / Cart : Exclude rewards for specific category
Created January 15, 2025 06:12
Cart : Exclude rewards for specific category
add_filter( 'fkcart_reward_enabled', function ( $status ) {
if ( is_null( WC()->cart ) ) {
return false;
}
$cart_items = WC()->cart->get_cart();
$tmp_category_id = [ 19 ]; // Your category ID here (for more categories, keep them comma separated)
foreach ( $cart_items as $cart_item ) {
@xlplugins
xlplugins / funnelkit_cart_reset_to_default_translate.php
Created January 13, 2025 12:48
FunnelKit cart Reset to Default text translate
add_action( 'fkcart_quick_before_view_content', function () {
add_filter( 'woocommerce_reset_variations_link', function () {
$text = '<a class="reset_variations" href="#">' . esc_html__( 'Reset to Default 21', 'woocommerce' ) . '</a>';
return $text;
} );
} );
@xlplugins
xlplugins / billing nif
Created January 10, 2025 11:45
billing nif
add_filter( 'wfacp_checkout_fields', function ( $template_fields, $fields ) {
if ( isset( $fields['billing']['billing_nif'] ) ) {
$template_fields['billing']['billing_nif'] = $fields['billing']['billing_nif'];
}
if ( isset( $fields['shipping']['shipping_nif'] ) ) {
$template_fields['shipping']['shipping_nif'] = $fields['shipping']['shipping_nif'];
@xlplugins
xlplugins / Save The NIF field
Created January 9, 2025 14:37
Save The NIF field
add_action('woocommerce_checkout_create_order',function ($order){
/**
* @var $order WC_Order
*/
if(isset($_POST['billing_nif'])){
$order->add_meta_data('billing_nif', $_POST['billing_nif']);
}
if(isset($_POST['shipping_nif'])){
$order->add_meta_data('shipping_nif', $_POST['shipping_nif']);
@xlplugins
xlplugins / Vipps to fkcart cart page
Created January 7, 2025 12:44
Vipps checkout button to fkcart cart page #FKCART
add_action( 'init', function () {
// Flytt Vipps-knappen fra cart actions til under proceed to checkout
remove_action( 'woocommerce_cart_actions', [ Vipps::instance(), 'cart_express_checkout_button' ] );
add_action( 'woocommerce_proceed_to_checkout', [ Vipps::instance(), 'cart_express_checkout_button' ], 20 );
add_action( 'fkcart_before_checkout_button', function () {
echo "<div class='fkcart-checkout-wrap fkcart-panel'>";
Vipps::instance()->cart_express_checkout_button();
echo "</div>";
}, 20 );
@xlplugins
xlplugins / automatically apply a coupon code when someone adds a specific product
Created January 3, 2025 06:19
automatically apply a coupon code when someone adds a specific product
add_action('woocommerce_add_to_cart', 'apply_coupon_on_specific_product');
function apply_coupon_on_specific_product($cart_item_key) {
$product_ids = array(93, 456); // Replace with your specific product IDs
$coupon_code = 'pro2'; // Replace with your coupon code
foreach (WC()->cart->get_cart() as $cart_item) {
if (in_array($cart_item['product_id'], $product_ids)) {
if (!WC()->cart->has_discount($coupon_code)) {
WC()->cart->apply_coupon($coupon_code);
@xlplugins
xlplugins / Server-side GTM integration
Last active January 3, 2025 04:33
Server-side GTM integration
// Define GTM Server Container URL (replace with your container endpoint)
$gtmEndpoint = "https://<your-gtm-server>.appspot.com";
// Example Conversion Data
$data = [
"event_name" => "purchase", // Event name, e.g., 'purchase', 'lead'
"conversion_tracking_id" => "AW-XXXXXXX", // Replace with your Google Ads conversion ID
"transaction_id" => "12345", // Unique transaction ID
"value" => 100.0, // Conversion value
"currency" => "USD", // Currency code
"user_data" => [
@xlplugins
xlplugins / fkwcs_statement_desc.php
Created January 2, 2025 07:50
Stripe Statement descriptor for non card transactions
/**
* Filter to add statement descriptor for payment intent request
*/
add_filter( 'fkwcs_payment_intent_data', function ( $request ) {
if ( true !== in_array( 'card', $request['payment_method_types'], true ) ) {
$request['statement_descriptor'] = 'YOUR_DESCRIPTOR_HERE';
}
return $request;
} );
@xlplugins
xlplugins / wffn_remove_stripe_toolbar_notice.php
Created December 30, 2024 10:40
wffn_remove_stripe_toolbar_notice.php
add_action( 'admin_head', function () {
if ( class_exists( 'WFFN_Stripe_Admin_Controller' ) ) {
remove_action( 'wp_before_admin_bar_render', [ WFFN_Stripe_Admin_Controller::get_instance(), 'custom_add_fk_stripe_menu' ] );
}
} );
@xlplugins
xlplugins / Checkout : landmark field in Shipping field
Created December 23, 2024 08:30
Checkout : landmark field in Shipping field
class WFACP_ADD_Custom_Fields_Under_Billing_Shipping {
public $custom_fields = [];
public function __construct() {
$this->assign_variables();
add_action( 'after_setup_theme', [ $this, 'setup_fields' ] );
}
public function assign_variables() {