Remove pagination trails from WooCommerce Breadcrumb

Today i am sharing small snippet that removes Pagination Trail from WooCommerce breadcrumbs.

Some shop owners may dislike this built-in feature and would like remove WooCommerce pagination links from WooCommerce navigation breadcrumb.

First let’s see how is before-after state of this change.

Before:

After:

Now let’s write a snippet for that:

Continue reading “Remove pagination trails from WooCommerce Breadcrumb”

Add custom recipient to WordPress comment notification

WordPress sends email notification to Comment Post Author by default. And if it is a reply, it also send a notification to the comment author.

So, what if we need to send email to a different person, using some different logic?

In that case we can use WP’s corresponding filter, called comment_notification_recipients.

This filter sits in wp-includes/pluggable.php.

So, we just add this small snippet to functions.php file of our active theme:

add_filter( 'comment_notification_recipients',function( $emails, $comment_ID){
    $emails[]='[email protected]';
    return $emails;
},10,2);

What if this email should be fetched by using some logic, f.e. there is special meta field in each post, where we need to fetch it from. Here is how it should look like:

add_filter( 'comment_notification_recipients',function( $emails, $comment_ID){
    $comment_obj=get_comment($comment_ID);
    if(!empty($comment_obj->comment_post_ID)){
        $email_owner=get_post_meta($comment_obj->comment_post_ID,
                      'email_meta_field',true); 
        if(is_email($email_owner))$emails[]=$email_owner;
    }
    return $emails;
},10,2);

That’s all. If any question on this subject, you can leave a reply. Don’t forget to subscribe my newsletter feed club to get more and more useful small snippets for WP websites.

Quick fix for Cloudflare and PHP REMOTE_ADDR IP Detection

Some CMS-s, Frameworks, Custom Codes have built-in functions on collecting user logs (registrations, updates, submits, payments etc.) where they are using PHP’s $_SERVER[“REMOTE_ADDR”] variable to get the visitor’s IP address.

But as you know very popular Cloudflare Cloud Service passes all your traffic through its own servers – and that’s why all log function which i mentioned above writes Cloudflare’s IP address to the DataBase, not visitor’s actual IP address.

What to do for that.

Continue reading “Quick fix for Cloudflare and PHP REMOTE_ADDR IP Detection”