Developer Reference¶
dms_woocommerce_product_args¶
Filters the values written to a product before it's saved. Receives the argument array, the WC_Product, and the Listing.
add_filter( 'dms_woocommerce_product_args', function ( array $args, $product, DMS\Listing $listing ): array {
// Keep sold vehicles out of the catalog rather than deleting the product.
if ( $listing->is_sold() ) {
$args['visibility'] = 'hidden';
$args['stock_status'] = 'outofstock';
}
return $args;
}, 10, 3 );
The array carries title, status, price, description, visibility, category_ids, stock_status, and manage_stock. An optional slug key is honoured if you add one:
add_filter( 'dms_woocommerce_product_args', function ( array $args, $product, DMS\Listing $listing ): array {
$args['slug'] = 'reserve-' . $listing->get_id();
return $args;
}, 10, 3 );
Every one of those values is written on each sync, so this filter is the supported way to customise a generated product — anything changed by hand in WooCommerce is overwritten the next time its listing is saved.
To keep a product's title independent of its listing, for instance:
add_filter( 'dms_woocommerce_product_args', function ( array $args, $product, DMS\Listing $listing ): array {
// Preserve whatever the product is currently called.
$args['title'] = $product->get_title();
return $args;
}, 10, 3 );
dms_woocommerce_deposit_sync()¶
Forces a product to re-sync. Useful after changing listing data programmatically, or from your own admin tooling.
// From a listing ID
dms_woocommerce_deposit_sync( $listing_id );
// From a product ID - resolves back to its listing first
dms_woocommerce_deposit_sync( $product_id, 'product' );
It runs the same routine as a save, so it creates the product if one doesn't exist yet.
Linking the two records¶
Each side stores a reference to the other:
| Meta key | Stored on | Holds |
|---|---|---|
dms_woo_id |
The listing | Its WooCommerce product ID |
dms_listing_id |
The product | Its DMS listing ID |
Both are plain post meta, so they're queryable. To find the listing behind an order item:
foreach ( $order->get_items() as $item ) {
$listing_id = (int) get_post_meta( $item->get_product_id(), 'dms_listing_id', true );
if ( $listing_id ) {
$listing = dms_get_listing( $listing_id );
// ...
}
}
A product whose ID no longer resolves is rebuilt automatically on the next sync, so a manually deleted product recovers rather than breaking.
Deposit calculation¶
Price is derived at sync time, not stored separately:
- Amount — the type's
woocommerce-deposits-deposit-amount, as-is. - Percentage — the listing's price multiplied by the type's percentage over 100.
Both are set as the product's price and regular price. To take a deposit that isn't a straight function of price — tiered by value, say — override price through dms_woocommerce_product_args.