Skip to content

Commit 54b8107

Browse files
authored
Merge pull request #371 from awesomemotive/feature/334-request-custom-filter
Add custom filters to allow modifying shortcodes and blocks conditions
2 parents f07dde4 + da9bfb8 commit 54b8107

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

inc/plugins/woocommerce/features/product-card.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,22 @@ function botiga_filter_loop_add_to_cart( $button, $product, $args ) {
219219
function botiga_page_has_woo_blocks() {
220220
global $post;
221221

222-
if( $post ) {
223-
if( isset( $post->post_content ) && strpos( $post->post_content, 'woocommerce/' ) ) {
224-
return true;
225-
}
222+
$result = false;
223+
if ( $post ) {
224+
if ( isset( $post->post_content ) && strpos( $post->post_content, 'woocommerce/' ) ) {
225+
$result = true;
226+
}
226227
}
227228

228-
return false;
229+
/**
230+
* Hook 'botiga_page_has_woo_blocks' to allow filtering the page whether a page has WooCommerce blocks.
231+
*
232+
* @param bool $result Whether the page has a WooCommerce block.
233+
* @param string $post_content string The content of the post.
234+
*
235+
* @since 2.3.4
236+
*/
237+
return apply_filters( 'botiga_page_has_woo_blocks', $result, $post->post_content );
229238
}
230239

231240
/**
@@ -240,17 +249,27 @@ function botiga_page_has_woo_shortcode() {
240249
'latest_arrivals', // third-party shortcode
241250
);
242251

243-
if( $post ) {
244-
if( isset( $post->post_content ) ) {
245-
foreach( $shortcodes as $shortcode ) {
246-
if( has_shortcode( $post->post_content, $shortcode ) ) {
247-
return true;
248-
}
249-
}
250-
}
252+
$result = false;
253+
if ( $post ) {
254+
if ( isset( $post->post_content ) ) {
255+
foreach ( $shortcodes as $shortcode ) {
256+
if ( has_shortcode( $post->post_content, $shortcode ) ) {
257+
$result = true;
258+
break;
259+
}
260+
}
261+
}
251262
}
252263

253-
return false;
264+
/**
265+
* Hook 'botiga_page_has_woo_shortcode' to allow filtering the page whether a page has the defined shortcodes.
266+
*
267+
* @param bool $result Whether the page has a WooCommerce shortcode.
268+
* @param string $post_content string The content of the post.
269+
*
270+
* @since 2.3.4
271+
*/
272+
return apply_filters( 'botiga_page_has_woo_shortcode', $result, $post->post_content );
254273
}
255274

256275
/**

0 commit comments

Comments
 (0)