Merge pull request #11619 from woothemes/fix/product-bulk-edit-webhook
Make sure product update webhook fires on bulk and quick edit.
This commit is contained in:
commit
1b71c1b0e7
|
@ -72,6 +72,9 @@ class WC_Install {
|
|||
'wc_update_260_refunds',
|
||||
'wc_update_260_db_version',
|
||||
),
|
||||
'2.7.0' => array(
|
||||
'wc_update_270_webhooks',
|
||||
),
|
||||
);
|
||||
|
||||
/** @var object Background update class */
|
||||
|
|
|
@ -270,6 +270,10 @@ class WC_Webhook {
|
|||
break;
|
||||
|
||||
case 'product':
|
||||
// bulk and quick edit action hooks return a product object instead of an ID
|
||||
if ( 'updated' === $event && is_a( $resource_id, 'WC_Product' ) ) {
|
||||
$resource_id = $resource_id->get_id();
|
||||
}
|
||||
$payload = WC()->api->WC_API_Products->get_product( $resource_id );
|
||||
break;
|
||||
|
||||
|
@ -581,6 +585,8 @@ class WC_Webhook {
|
|||
'product.updated' => array(
|
||||
'woocommerce_process_product_meta',
|
||||
'woocommerce_api_edit_product',
|
||||
'woocommerce_product_quick_edit_save',
|
||||
'woocommerce_product_bulk_edit_save',
|
||||
),
|
||||
'product.deleted' => array(
|
||||
'wp_trash_post',
|
||||
|
|
|
@ -970,3 +970,20 @@ function wc_update_260_refunds() {
|
|||
function wc_update_260_db_version() {
|
||||
WC_Install::update_db_version( '2.6.0' );
|
||||
}
|
||||
|
||||
function wc_update_270_webhooks() {
|
||||
/**
|
||||
* Make sure product.update webhooks get the woocommerce_product_quick_edit_save
|
||||
* and woocommerce_product_bulk_edit_save hooks.
|
||||
*/
|
||||
$product_update_webhooks = get_posts( array(
|
||||
'posts_per_page' => -1,
|
||||
'post_type' => 'shop_webhook',
|
||||
'meta_key' => '_topic',
|
||||
'meta_value' => 'product.updated'
|
||||
) );
|
||||
foreach ( $product_update_webhooks as $product_update_webhook ) {
|
||||
$webhook = new WC_Webhook( $product_update_webhook->ID );
|
||||
$webhook->set_topic( 'product.updated' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue