SquareWooSync Pro Hooks Reference #
Complete reference for all filters and actions available in SquareWooSync Pro plugin.
Filters #
squarewoosync_prepare_order_data #
Location: includes/REST/OrdersController.php:539
Modify Square order data before it’s sent to the Square API when creating orders from WooCommerce.
add_filter('squarewoosync_prepare_order_data', function($order_data, $wc_order) {
// Modify the order data array
return $order_data;
}, 10, 2);
$order_data
(array) – Square order data structure$wc_order
(WC_Order) – WooCommerce order object
squarewoosync_create_square_customer_payload #
Location: includes/Customer/Customers.php:101
Modify the Square customer payload before creating a new customer in Square.
add_filter('squarewoosync_create_square_customer_payload', function($payload, $user_id, $settings) {
// Add or modify customer data
$payload['company_name'] = get_user_meta($user_id, 'billing_company', true);
return $payload;
}, 10, 3);
$payload
(array) – Square customer data payload$user_id
(int) – WordPress user ID$settings
(array) – Plugin settings array
squarewoosync_square_customer_payload #
Location: includes/Customer/Customers.php:562
Modify the Square customer payload when updating or creating customer from order data.
add_filter('squarewoosync_square_customer_payload', function($payload, $customer, $settings) {
// Modify customer data from order
return $payload;
}, 10, 3);
$payload
(array) – Square customer data payload$customer
(WC_Order|object) – WooCommerce customer/order object$settings
(array) – Plugin settings array
squarewoosync_skip_variation_sync #
Location: includes/Woo/SyncProduct.php:811
, includes/Woo/WooImport.php:916
Control whether a specific product variation should be skipped during synchronization.
add_filter('squarewoosync_skip_variation_sync', function($skip, $variation_id, $variation) {
// Skip variations with specific attributes
if ($variation && $variation->get_attribute('color') === 'discontinued') {
return true;
}
return $skip;
}, 10, 3);
$skip
(bool) – Default skip status based on meta$variation_id
(int) – Variation product ID$variation
(WC_Product|null) – Variation product object
squarewoosync_order_location_id #
Location: includes/REST/OrdersController.php:430
Override the Square location ID for a specific order.
add_filter('squarewoosync_order_location_id', function($location_id, $order) {
// Use different location based on shipping zone
$shipping_country = $order->get_shipping_country();
if ($shipping_country === 'CA') {
return 'CANADA_LOCATION_ID';
}
return $location_id;
}, 10, 2);
$location_id
(string) – Default Square location ID$order
(WC_Order) – WooCommerce order object
sws_discount_priority #
Location: includes/Discount/DiscountApplicator.php:53
Set the priority for discount calculations.
add_filter('sws_discount_priority', function($priority) {
// Change discount calculation priority
return 10; // Higher priority
});
$priority
(int) – Default priority (99)
sws_api_controllers #
Location: includes/REST/Api.php:37
Register custom REST API controllers.
add_filter('sws_api_controllers', function($controllers) {
// Add custom API controller
$controllers['custom'] = 'My\Custom\Controller';
return $controllers;
});
$controllers
(array) – Array of controller class names
sws_is_local_development #
Location: includes/Queue/QueueConnectionResolver.php:168
Override local development detection for queue processing.
add_filter('sws_is_local_development', function($is_local) {
// Force production mode even on localhost
return false;
});
$is_local
(bool) – Whether environment is detected as local
sws_redis_config #
Location: includes/Queue/QueueConnectionResolver.php:212
Configure Redis connection for queue processing.
add_filter('sws_redis_config', function($config) {
// Custom Redis configuration
$config['host'] = 'redis.example.com';
$config['port'] = 6380;
$config['password'] = 'secret';
return $config;
});
$config
(array) – Redis configuration array
sws_allowed_job_classes #
Location: includes/Queue/QueueConnectionResolver.php:229
Add custom job classes to the allowed queue jobs list.
add_filter('sws_allowed_job_classes', function($allowed_jobs) {
// Add custom job class
$allowed_jobs[] = 'My\Custom\Job';
return $allowed_jobs;
});
$allowed_jobs
(array) – Array of allowed job class names
Actions #
squarewoosync_square_order_created #
Location: includes/Woo/SyncOrder.php:498
, includes/REST/OrdersController.php:145
Fired after a Square order is successfully created from a WooCommerce order.
add_action('squarewoosync_square_order_created', function($square_order_id, $wc_order_id) {
// Send notification, update external systems, etc.
error_log("Square order $square_order_id created for WooCommerce order $wc_order_id");
}, 10, 2);
$square_order_id
(string) – Square order ID$wc_order_id
(int) – WooCommerce order ID
squarewoosync_square_order_imported #
Location: includes/Woo/CreateOrder.php:216
Fired after a WooCommerce order is created from a Square order (import direction).
add_action('squarewoosync_square_order_imported', function($square_order_id, $wc_order_id) {
// Process imported order
$order = wc_get_order($wc_order_id);
// Custom processing...
}, 10, 2);
$square_order_id
(string) – Square order ID$wc_order_id
(int) – Created WooCommerce order ID
squarewoosync_product_created #
Location: includes/Woo/CreateProduct.php:109
Fired after a WooCommerce product is created from Square catalog data.
add_action('squarewoosync_product_created', function($product_id, $square_item_id, $square_data) {
// Additional product setup after import
update_post_meta($product_id, '_custom_field', 'imported_from_square');
}, 10, 3);
$product_id
(int) – Created WooCommerce product ID$square_item_id
(string) – Square catalog item ID$square_data
(array) – Square item data
sws_line_discount_done #
Location: includes/Discount/DiscountApplicator.php:209
Fired after line item discounts have been applied to the cart.
add_action('sws_line_discount_done', function() {
// Perform actions after discount calculation
WC()->cart->calculate_totals();
});
sws_order_import_completed #
Location: includes/Jobs/OrderImportJob.php:575
Fired when a batch order import job is completed.
add_action('sws_order_import_completed', function($progress) {
// Send notification about import completion
$admin_email = get_option('admin_email');
wp_mail($admin_email, 'Order Import Completed',
"Import completed. Processed: {$progress['processed']}, Failed: {$progress['failed']}");
});
$progress
(array) – Import progress data with processed/failed counts
squarewoosync_payment_updated #
Location: includes/Payments/WC_SquareSync_Gateway.php:1823
Fired after a Square payment is updated.
add_action('squarewoosync_payment_updated', function($order_id, $payment_id, $payment_data) {
// Log payment updates
$order = wc_get_order($order_id);
$order->add_order_note("Square payment $payment_id updated");
}, 10, 3);
$order_id
(int) – WooCommerce order ID$payment_id
(string) – Square payment ID$payment_data
(array) – Payment update data
squarewoosync_payment_completed #
Location: includes/Payments/WC_SquareSync_Gateway.php:1973
Fired when a Square payment is completed successfully.
add_action('squarewoosync_payment_completed', function($order_id, $payment_id, $payment_data) {
// Trigger post-payment actions
do_action('my_custom_payment_success', $order_id);
}, 10, 3);
$order_id
(int) – WooCommerce order ID$payment_id
(string) – Square payment ID$payment_data
(array) – Payment completion data
Usage Examples #
Example: Custom Order Processing #
// Modify order data before sending to Square
add_filter('squarewoosync_prepare_order_data', function($order_data, $wc_order) {
// Add custom metadata
$order_data['order']['metadata']['source_campaign'] = 'summer_sale';
// Modify based on customer group
if (wc_user_has_role($wc_order->get_customer_id(), 'wholesale')) {
$order_data['order']['metadata']['customer_type'] = 'wholesale';
}
return $order_data;
}, 10, 2);
// React to successful order creation
add_action('squarewoosync_square_order_created', function($square_order_id, $wc_order_id) {
// Update inventory in external system
$order = wc_get_order($wc_order_id);
foreach ($order->get_items() as $item) {
// Sync with external inventory system
do_action('external_inventory_update', $item->get_product_id(), $item->get_quantity());
}
}, 10, 2);
Example: Selective Product Sync #
// Skip certain variations from syncing
add_filter('squarewoosync_skip_variation_sync', function($skip, $variation_id, $variation) {
// Skip out-of-stock variations
if ($variation && !$variation->is_in_stock()) {
return true;
}
// Skip variations with specific SKU pattern
if ($variation) {
$sku = $variation->get_sku();
if (strpos($sku, 'NOSYNC-') === 0) {
return true;
}
}
return $skip;
}, 10, 3);
Example: Multi-Location Support #
// Route orders to different Square locations
add_filter('squarewoosync_order_location_id', function($location_id, $order) {
// Map shipping zones to Square locations
$shipping_zone = WC_Shipping_Zones::get_zone_matching_package([
'destination' => [
'country' => $order->get_shipping_country(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
]
]);
$zone_name = $shipping_zone->get_zone_name();
$location_map = [
'East Coast' => 'LOCATION_ID_EAST',
'West Coast' => 'LOCATION_ID_WEST',
'International' => 'LOCATION_ID_INTL',
];
return $location_map[$zone_name] ?? $location_id;
}, 10, 2);
Best Practices #
- Priority Management: Use appropriate priority values (default is 10) to ensure your hooks run in the correct order.
- Error Handling: Always validate data and handle potential errors gracefully in your hook callbacks.
- Performance: Avoid heavy operations in filters that run during checkout or payment processing.
- Return Values: Always return the expected data type from filters to avoid breaking the plugin functionality.
- Testing: Test your customizations thoroughly, especially those affecting payment and order processing.