Hide one specific woocoomerce product

This code is tested and works fine on a fresh WP and WooCommerce installation. if ( !is_user_logged_in()) { function exclude_product_from_users($q){ $current_user = wp_get_current_user(); $prodcuts_ids = array(648); $q->set( ‘post__not_in’, $prodcuts_ids ); } add_action( ‘woocommerce_product_query’, ‘exclude_product_from_users’ ); function return_from_product_page(){ global $post; $prodcuts_ids = array(648); if(in_array( $post->ID , $prodcuts_ids)){ wp_redirect(home_url(“https://wordpress.stackexchange.com/”)); exit(); } } add_action(‘wp’, ‘return_from_product_page’); }

How can I override wp_price woocommerce function in my theme

Hmm how about this? function return_custom_price($price, $product) { global $post, $blog_id; $price = get_post_meta($post->ID, ‘_regular_price’); $post_id = $post->ID; $price = ($price[0]*2.5); return $price; } add_filter(‘woocommerce_get_price’, ‘return_custom_price’, 10, 2); Taken from here:https://sceptermarketing.com/how-to-change-the-woocommerce-price-via-functions-php/

Configure WordPress to Generate Scheme-less Relative URLs

You can use the style_loader_src and script_loader_src filters. namespace WPSE; \add_filter( ‘style_loader_src’ , __NAMESPACE__ . ‘\protocol_relative-url’ ); \add_filter( ‘script_loader_src’, __NAMESPACE__ . ‘\protocol_relative-url’ ); function protocol_relative_url( string $url ) : string { return str_replace( [ ‘http:’, ‘https:’ ], ”, $url ); } /* Notes: * Namespaces require PHP > 5.3 * [] array syntax requires PHP … Read more

WordPress media library allow uploading fake file

If the file isn’t an image, its mime type is checked against the allowed list. As your example would generate a text mimetype, and it’s an allowed file extension, it passes through. There should be no concern unless your server is executing image files as PHP, in which case this issue is the least of … Read more

Advanced WordPress plugin activation detection

The init and plugins_loaded hooks are already run before a plugin is activated. That’s why your first code doesn’t work but the second does. Regarding your third code: there’s no need to run add_action(‘myplugin_activate’ … inside init. Not everything needs to be hooked to init. Just use add_action(‘myplugin_activate’, function(){ echo ‘myplugin is not allowed.’; die; … Read more

Remove action within a class in a parent theme’s includes folder from the child theme

Thanks a lot to Nathan Johnson: The solution was to use instance of the class the action was defined in. The class was globalized in the theme after instantiation. So the adding the below code to functions.php of a Child Theme worked: function remove_woo_forms_hooks() { global $woo_a; remove_action(‘woocommerce_before_customer_login_form’, array($woo_a,’before_customer_login_form’)); } add_action( ‘after_setup_theme’, ‘remove_woo_forms_hooks’,0);

Conditional action hook

Woocommerce adds the action hook at priority order 30. add_action(‘woocommerce_single_product_summary’,’woocommerce_template_single_add_to_cart’,30); So, You may have done remove_action(‘woocommerce_single_product_summary’,’woocommerce_template_single_add_to_cart’,30); to remove the action from the hook. To remove an action the priority must match the priority with with the function was originally added. Now you can do function add_cart_button(){ global $product; $id = $product->get_id(); if($id != 1345 ): … Read more