我有以下代码来覆盖webhook构建过程,如果产品是可变的,则添加变体对象:
// Hook to the webhook build process and add your variations objects.
add_filter( 'woocommerce_webhook_payload', 'dolly_woocommerce_webhook_payload', 10, 4 );
function dolly_woocommerce_webhook_payload( $payload, $resource, $resource_id, $id ) {
// Remove the filter to eliminate the recursion calls.
remove_filter( 'woocommerce_webhook_payload', 'dolly_woocommerce_webhook_payload', 10 );
// Create a WC_Webhook class with the webhook id.
$wc_webhook = new WC_Webhook( $id );
// Bail early if the resource is not product.
if ( 'product' !== $resource ) {
return $payload;
}
// Bail early if the product type is not variable.
$product = new WC_Product( $resource_id );
if ( 'variable' === $product->get_type() ) {
return $payload;
}
// Build the payload of each product variation.
$variations = $payload['variations'];
foreach( $variations as $variation ) {
$variations_objs[] = $wc_webhook->build_payload( $variation );
}
// Add the varitions to the payload.
$payload['variations_objs'] = $variations_objs;
// Add the filter again and return the payload.
add_filter( 'woocommerce_webhook_payload', 'dolly_woocommerce_webhook_payload', 10, 4 );
return $payload;
}
不幸的是,当在变体处于活动状态时在变体上点击“保存更改”时,变体不会停止保存。
我收到的有效负载似乎是保存过程完成之前的负载,而不是之后的负载。因此,基本上,以前输入的值就好像还没有发生。
谢谢!