PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Custom code snippets not working after filter

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

hey, I want to add custom code snippets to the woocommerce shop loop. This works as long as I not filter the products. When I use the filter the snippets are not working anymore. Info: I need to use ajax filter

Because of this problem I also cant use the slideout shortcode. Afer I filter the slideout is not showing anymore.

Hello

Please drop  me  exact  link to the  issue

Describe  in  more  datail  your  custon  code

difloraplant.it/shop

my main problem is that I cant add anything to the shop page as soon as I filter, all of my changes disappear. I added some snippets to show a new badge next to the product image

I want to add the slideout shortcode because when I say place the slideout everywhere it also place it on mobile even when I say dont show on mobile!

But when I add the shortcode and i filter on the shoppage it slideout is gone. It somehow always load  the default shop loop without my changes.

Hello

Please paste your license key here - https://share.pluginus.net/image/i20230222134241.png -> https://share.pluginus.net/image/i20230222134511.png

Try to disable  ajax   and  do  a  test

Yes it is working without ajax. But I need to use ajax.

Hello

Ok! So you need to make customizations so that they work (are compatible) with ajax mode

This of course depends on the type of customization and where you insert your custom code.

For exmaple I want to use this shortcode on the shop page: [woof_slideout image=/wp-content/uploads/2023/05/filter.png image_h=38 image_w=142 location=left speed=100 action=click offset=45px onloadslideout=false mobile_behavior=2 ][/woof_slideout]

but when I filter the slideout is gone

 

same for this code snippet:

// New badge for recent products
add_action( 'woocommerce_before_shop_loop_item', 'new_badge', 40 );

function new_badge() {
$product = wc_get_product( get_the_ID() );
$newness_days = 30; // Number of days the badge is shown
$created = strtotime( $product->get_date_created() );
if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
echo '<span class="new-badge onsale">' . esc_html__( 'NEW', 'woocommerce' ) . '</span>';
}
}

 

which adds a new badge to the products at front end shop page.

 

Please filter at my shop page then you will se it.

 

Please add  exact  link  to the  issue

Where did you put your custom code.

is this an automatic answer?

here is the link: difloraplant.it/shop

I put the shortcode to the shop page and the code snippet to an code snippet plugin.

hello

the shop page and the code snippet to an code snippet plugin. -Ok!  Please  paste it  in functions.php

but when I filter the slideout is gone - My  test - https://c2n.me/4iWM6FH - slide out does not disappear, maybe I'm doing something wrong

i cant create a child theme so I cant paste it in the functions.php, why is it not working with the snippet plugin?

The slideout is now working as it should

hello

This means that the snippet plugin does not work (is not compatible) with ajax mode.  Why this third party plugin doesn't add snippets in Ajax mode, unfortunately I don't know, it has nothing to do with my plugin

I tried the most popular snippet plugins and it does not work for both.

this is one snippet I am using but it dissapear when I filter in ajax mode:

 

// New badge for recent products
add_action( 'woocommerce_before_shop_loop_item', 'new_badge', 40 );

function new_badge() {
$product = wc_get_product( get_the_ID() );
$newness_days = 30; // Number of days the badge is shown
$created = strtotime( $product->get_date_created() );
if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
echo '<span class="new-badge onsale">' . esc_html__( 'NEW', 'woocommerce' ) . '</span>';
}
}

 

 

 

Hello

Ok! I'll try to explain it differently:  It doesn't matter which plugin will make the ajax request if the snippet plugin is not compatible with ajax

My plugin uses the current theme products template.   and  all the hooks of this template work.

If you are interested in knowing the reason for the technical side:  I think the problem is that the ajax request in the WP is executed in the admin area (wp-admin url ).  And these snippet plugins have code that prevents scripts from being executed on the side of the admin panel. An  example:

if (is_admin()){

return false;

}

The solution for such situations can be to check if the current request is AJAX:

if (is_admin() && !wp_doing_ajax()) {

return false;

}