Wodpress XML Import hooks

This is slightly complicated. I could think of 3 ways to do this: Use someone else’s importer plugin. Importing stuff into WP using complicated criteria is a solved problem. However, I’ve never met an importer plugin that I liked which was free. Most of the projects I work on have less cash and more developer … Read more

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more

Display product thumbnail in Woocommerce email notifications

You’d better use woocommerce_email_order_items_args filter. It can be done this way: function add_product_thumbnail_to_wc_emails( $args ) { $args[‘show_image’] = true; $args[‘image_size’] = array( 100, 100 ); return $args; } add_filter( ‘woocommerce_email_order_items_args’, ‘add_product_thumbnail_to_wc_emails’ ); The code has to be placed to functions.php

Correct Hook/Filter to amend category choices on post edit page

I managed to solve this issue using pre_get_termsas an action and then updating the query_vars $current_user = get_current_user_id(); $user_field = “user_”.$current_user; $user_categories = get_field(‘post_categories’, $user_field); if(in_array(‘category’,$terms->query_vars[‘taxonomy’])){ $terms->query_vars[‘include’] = $user_categories; } return $terms;

Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint

I figured out it could be an Authorization problem, then I looked the WooCommerce webhook functions and fount where the delivery is executed: /wp-content/plugins/woocommerce/includes/class-wc-webhook.php I hard coded my Authorization header after line # 303 in the deliver() function: ‘headers’ => array( ‘Content-Type’ => ‘application/json’, ‘Authorization’ => ‘Basic bmNkaWgdrGFsOiNIb25kdXJhczIwMThTUFMh’, ), Now I need to calculate the … Read more

WordPress wp_get_current_user returning blank values until refresh

Your header.php file is going to be called after the init action. If you want the logic to run in your header.php file first, maybe you can hook into another action done at a later point in WordPress: add_action(‘wp_head’, ‘ax_get_user_info’); function avox_get_user_info() { if (is_user_logged_in()) { $currentUser = wp_get_current_user(); $fName = $currentUser->user_firstname; } return $fName; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)