feat: optionally create missing WooCommerce products from BC items
The plugin only ever updated existing WooCommerce products - nothing created new ones, so a category-filtered sync would just skip every BC item without a matching product, no matter how the filter was configured. Adds an opt-in "Create Missing Products" setting (default off, so existing update-only behavior is unchanged unless explicitly enabled) that creates a bare WC_Product_Simple (name, SKU from GTIN/number, configurable draft/publish status) for unmatched BC items in the category-filtered sync path, then runs it straight through the existing update_product() call for stock/price/brand - no duplicated logic. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,6 +89,12 @@ class WBC_Admin {
|
||||
register_setting( 'wbc_sync', 'wbc_category_parent_map', array(
|
||||
'sanitize_callback' => 'sanitize_textarea_field',
|
||||
) );
|
||||
register_setting( 'wbc_sync', 'wbc_create_missing_products', array(
|
||||
'sanitize_callback' => array( $this, 'sanitize_checkbox' ),
|
||||
) );
|
||||
register_setting( 'wbc_sync', 'wbc_new_product_status', array(
|
||||
'sanitize_callback' => array( $this, 'sanitize_new_product_status' ),
|
||||
) );
|
||||
|
||||
// Order settings (own group)
|
||||
register_setting( 'wbc_orders', 'wbc_enable_order_sync', array(
|
||||
@@ -173,6 +179,16 @@ class WBC_Admin {
|
||||
return $value === 'yes' ? 'yes' : 'no';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the new-product status setting
|
||||
*
|
||||
* @param string $value Input value.
|
||||
* @return string 'publish' or 'draft'.
|
||||
*/
|
||||
public function sanitize_new_product_status( $value ) {
|
||||
return $value === 'publish' ? 'publish' : 'draft';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue admin scripts
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user