a-ok Posted June 17, 2021 Share Posted June 17, 2021 I've added a page hook method (addHookMethod) in ready.php and I am calling it on a page. Simple enough. See below for the current code. I now need to pass parameters into the hook but can't figure out how this is possible? So with the current usage here: $product = $page->shopifyGetProductById(); I'd like to pass some parameters into the hook to then use within the hook function itself: $product = $page->shopifyGetProductById($data); wire()->addHookMethod('Page::shopifyGetProductById', function($event) { $page = $event->object; $gid = "gid://shopify/Product/{$page->shopifyProductId}"; $query = <<<GQL query { product(id: "$gid") { title } } GQL; $result = wire('cache')->get("shopifyGetProductById{$page->shopifyProductId}"); if (!$result) { $result = shopifyGQL($query); wire('cache')->save("shopifyGetProductById{$page->shopifyProductId}", $result, "template=shopifyProduct, shopifyProductId={$page->shopifyProductId}"); } $event->return = $result; }); Link to comment Share on other sites More sharing options...
elabx Posted June 18, 2021 Share Posted June 18, 2021 This works?? $data = $event->arguments(0); 1 Link to comment Share on other sites More sharing options...
a-ok Posted June 18, 2021 Author Share Posted June 18, 2021 5 hours ago, elabx said: This works?? $data = $event->arguments(0); This does work! I'm sorry for the clearly amateur question! Thanks! 1 Link to comment Share on other sites More sharing options...
elabx Posted June 18, 2021 Share Posted June 18, 2021 4 hours ago, a-ok said: This does work! I'm sorry for the clearly amateur question! Thanks! No worries, 'keep em coming! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now