Importing Custom Headers for WooCommerce Products & Variations with WPSyncSheets for WooCommerce
You may have custom columns in Google Sheets that store additional data for WooCommerce product variations, such as internal reference codes, external system IDs, or custom attributes.
Using WPSyncSheets, you can import these values and save them as variation meta in WooCommerce.
The following steps explain how to register and import custom headers for product variations.
Step 1: Register the Custom Header
Register the custom header so it is available for variation product import.
Headers must be returned as an associative array in the format:
meta_key => Column Label
add_filter( 'wpssw_headers_for_variation_product_import', function ( $headers ) {
$headers = array(
'variation_supplier_code' => 'Variation Supplier Code',
);
return $headers;
});
Step 2: Apply the Header Only to Variations (Exclude Parent Product)
If the custom header is only for variation products, use this filter to exclude it from the parent product.
add_filter( 'wpssw_custom_headers_for_variation_product_import', function ( $headers ) {
$headers = array(
'variation_supplier_code' => 'Variation Supplier Code',
);
return $headers;
});
Step 3: Handle the Import Logic
Override the default import behavior and store the imported value as variation meta.
add_filter(
'wpssw_custom_headers_for_product_variation_doimport',
function ( $override, $product_id, $meta_key, $meta_value ) {
if ( $meta_key === 'variation_supplier_code' ) {
update_post_meta( $product_id, 'variation_supplier_code', $meta_value );
return true;
}
return $override;
},
10,
4
);
This filter provides the following parameters to control how variation custom headers are imported.
| Parameter | Description |
|---|---|
$override | Default value. Return a non-null value (e.g. true) to stop default handling |
$product_id | The variation product ID |
$meta_key | The meta key (header key) being imported |
$meta_value | The value from Google Sheets for this variation |