admin管理员组

文章数量:1122846

I’m trying to implement a frontend WC block hook, but unfortunately I’m not able to trigger it. I’m using a fresh 8.7.0 install, and blocks are definitely enabled. I’ve tried following the instructions for @wordpress/hooks to either use the defaultHooks.addAction or create a custom object (myObj.hooks.addAction) but I can’t get any WC block events to register with my functions. Here’s an example:

import { createHooks } from "@wordpress/hooks";

let example = {}
example.hooks = createHooks();

example.hooks.addAction(
  "experimental__woocommerce_blocks-cart-add-item",
  "getverdict/real-id/item-added",
  () => {
    console.debug("WC :: cart item added");
 
    debugger;
  },
  1
);

But the listener never fires.

I’ve also tried:

import { defaultHooks } from "@wordpress/hooks";

defaultHooks.addAction(
  "experimental__woocommerce_blocks-cart-add-item",
  "getverdict/real-id/item-added",
  () => {
    console.debug("WC :: cart item added");
 
    debugger;
  },
  1
);

But when I add an item to the cart, the function doesn’t fire. Anyone else using these JS hooks?

As another test, I've tried listening to the all event, but also no luck.

Any help would be appreciated.

本文标签: block editorUnable to trigger a frontend wordpresshooks action