Archived topic
Woocommerce endpoints
9 replies · Started by Ketil on July 1, 2022
Hi. Can I filter a hook to show by woocommerce endpoints?
Hi there,
woocommerce provides the is_wc_endpoint_url template tag.
Heres an example using that with a GP Element.
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 100 === $element_id && is_wc_endpoint_url( 'order-received' ) ) {
$display = false;
}
return $display;
}, 10, 2 );
the 100 is the ID of the GP Element. And if the is_wc_endpoint_url( 'order-received' ) condition is met then the Element will be disabled ( $display = false; )
If you have a specific requirement let me know.
I made a custom endpoint for easy access to some extra functions I have added to site. Just to make it easy to find for the customers. I wanted to create a hooks in order to display some extra admin-options for this endpoint, active only for /my-account/my-endpoint
have you created your own template for /my-endpoint ?
Yes, using an Elementor template by shortcode. Can be solved in the template, I guess.
Yes, you would need to include that in the template.
If its built with Elementor then GP hooks won't work as they do not exist outside of the theme templates.
The initial idea was to show these admin options as a hook not connected to the page content, like you can for regular pages and posts, the content of the page/post can be Elementor, but you can still hook "after content" etc. I guess you can hook the page "my-account", but it will show no matter what endpoint is navigated, right?
GP doesn't add Woocommerce templates, it leaves that to the Woo plugin.
So you need to check which template is being used. How did you create the endpoint template ?
"My account" is not a Woocommerce template as such, it's a regular page with a shortcode in it. But nevermind, I'll solve it in the template instead of by a hook
Ok, no problem, it make the most sense to edit the page/template if its accessible.
Hooks are good for when you can't do that.