WPSyncSheets For WooCommerce

Documentation

Filters, Hooks & Snippets – WPSyncSheets For WooCommerce

Update Synchronization Limit

By default, this plugin has a synchronization limit set to 500 for the total order/product/customer/coupon/event count above 2000.

If you are having an issue related to the limit or you just want to increase or decrease the limit as per your server configuration requirement you can add this filter to your theme’s functions.php file.

To change the order sync limit to 200

function update_sync_limit(){
      return 200;
}
add_filter(  'wpssw_order_sync_limit', 'update_sync_limit' );

To change the product sync limit to 150

function update_sync_limit(){
      return 150;
}
add_filter(  'wpssw_product_sync_limit', 'update_sync_limit' );

To change the coupon sync limit to 100

function update_sync_limit(){
      return 100;
}
add_filter(  'wpssw_coupon_sync_limit', 'update_sync_limit' );

To change the customer sync limit to 200

function update_sync_limit(){
      return 200;
}
add_filter(  'wpssw_customer_sync_limit', 'update_sync_limit' );

To change the event sync limit to 300

function update_sync_limit(){
      return 300;
}
add_filter(  'wpssw_event_sync_limit', 'update_sync_limit' );

How to add your own custom field?

You can add a custom meta key with the prefix ‘wpsyncsheets_’ and our plugin will automatically detect those custom fields and add them to the headers.

// Add a metabox.
add_action( 'add_meta_boxes', 'add_custom_abcd_meta_box' );

function add_custom_abcd_meta_box() {
  
  add_meta_box(
    'custom_meta_box',
    __( 'My Custom Meta Box', 'woocommerce' ),
    'custom_abcd_metabox_content_callback',
    'shop_order'
  );

}

// For displaying metabox content
function custom_abcd_metabox_content_callback( $post ) {
  
  $abcd = get_post_meta( $post->ID, 'wpsyncsheets_abcd', true );

  echo '<p>' . __( 'ABCD', 'woocommerce' ) . '<br>
  <input type="text" style="width:100%" id="abcd" name="abcd" value="' . esc_attr( $abcd ) . '"></p>';

}
// For saving the metabox data.
add_action( 'save_post_shop_order', 'save_custom_abcd_meta_box_data' );

function save_custom_abcd_meta_box_data( $post_id ) {
   
  if ( isset( $_POST['abcd'] ) ) {
      // Update the meta field in the database.
      update_post_meta( $post_id, 'wpsyncsheets_abcd', sanitize_text_field( $_POST['abcd'] ) );
  }

}

Prevent Google Sheets Row Formatting Inheritance

When inserting rows into Google Sheets via the API, Google Sheets may automatically copy formatting (background color, font styles, bold text, etc.) from adjacent rows. This often causes header styling or previously formatted rows to be unintentionally applied to newly inserted or updated rows.

Disable Formatting Inheritance

Add the following filter to your theme’s functions.php file or a custom plugin:

// Disable style inheritance when inserting rows into Google Sheets.
add_filter( 'wpssw_insert_dimension_inherit_from_before', '__return_false' );

How to add your own custom field?

WPSyncSheets allows developers to register custom headers dynamically for Orders and Products.

This feature is useful when you want to:

  • Add custom spreadsheet columns
  • Populate custom meta values
  • Show custom headers inside Add Headers From Source
  • Extend plugin functionality without editing core files

Important

To fully register a custom header, two registrations are required:

1. Register the Header and Value

This allows WPSyncSheets to calculate and sync the value.

2. Register the Header Source

This makes the header appear in the Add Headers From Source dropdown.

Without source registration, the header will sync internally but will not be selectable in the UI.

Add Custom Order Headers

Use the following filters:

  • wpssw_custom_header
  • swpssw_custom_values
  • wpssw_order_header_sources

Example: Referral Code and Internal Note

/**
 * Order custom headers.
 */
function my_wpssw_order_custom_headers() {
	return array(
		'Referral Code',
		'Internal Note',
	);
}

add_filter(
	'wpssw_custom_headers',
	function ( $headers ) {
		return array_merge( $headers, my_wpssw_order_custom_headers() );
	}
);

add_filter(
	'wpssw_custom_values',
	function ( $value, $order_id, $header_name ) {
		$order = wc_get_order( $order_id );

		if ( ! $order ) {
			return $value;
		}

		if ( 'Referral Code' === $header_name ) {
			return $order->get_meta( '_referral_code', true );
		}

		if ( 'Internal Note' === $header_name ) {
			return $order->get_meta( '_internal_note', true );
		}

		return $value;
	},
	10,
	3
);

add_filter(
	'wpssw_order_header_sources',
	function ( $sources ) {
		$sources[] = array(
			'id'               => 'my_order_custom_headers',
			'label'            => 'My Order Custom Headers',
			'searchable'       => true,
			'headers_callback' => 'my_wpssw_order_custom_headers_for_source',
		);

		return $sources;
	}
);

function my_wpssw_order_custom_headers_for_source( $args ) {
	$search = isset( $args['search'] ) ? strtolower( $args['search'] ) : '';
	$items  = array();

	foreach ( my_wpssw_order_custom_headers() as $header ) {
		if ( '' !== $search && false === strpos( strtolower( $header ), $search ) ) {
			continue;
		}

		$items[] = array(
			'key'   => $header,
			'label' => $header,
		);
	}

	return $items;
}

Add Custom Product Headers

Use the following filters:

  • wpssw_custom_headers_for_product
  • wpssw_custom_values_for_product
  • wpssw_product_header_sources

Example: Supplier Code

function my_wpssw_product_custom_headers() {
	return array(
		'Supplier Code',
	);
}

add_filter(
	'wpssw_custom_headers_for_product',
	function ( $headers ) {
		return array_merge( $headers, my_wpssw_product_custom_headers() );
	}
);

add_filter(
	'wpssw_custom_values_for_product',
	function ( $value, $product_id, $header_name ) {
		if ( 'Supplier Code' === $header_name ) {
			return get_post_meta( $product_id, '_supplier_code', true );
		}

		return $value;
	},
	10,
	3
);

add_filter(
	'wpssw_product_header_sources',
	function ( $sources ) {
		$sources[] = array(
			'id'              => 'my_product_custom_headers',
			'label'           => 'My Product Custom Headers',
			'searchable'      => true,
			'headers_callback'=> 'my_wpssw_product_custom_headers_for_source',
		);

		return $sources;
	}
);

function my_wpssw_product_custom_headers_for_source() {
	return array_map(
		function ( $header ) {
			return array(
				'key'   => $header,
				'label' => $header,
			);
		},
		my_wpssw_product_custom_headers()
	);
}

Header Key Matching

The header key returned by the source callback must exactly match the registered custom header name.

Correct

'Referral Code'

Incorrect

'referral_code'

Real-Time Import, Export, and Migration of WooCommerce Data.

WPSyncSheets For WooCommerce

5.0
View Plugin

Have a question?

We’re here to help, just send us a message.

Need help?

We're ready to help out & answer questions!