Remove an action by extending class and replacing it

Problem lies in this line: remove_action(‘woocommerce_before_my_account’, array( $this, ‘my_packages’)); This won’t remove action registered by parent class, because $this is a different object in this case, so you won’t remove any action at all. So how to remove such action? Since you can’t access the same $this value in your class, you’ll have to iterate … Read more

WooCommerce – Conditionally enable shipping for virtual products

You can try following code: add_filter(‘woocommerce_cart_needs_shipping_address’,’fun_return_shipping_param’); function fun_return_shipping_param($needs_shipping_address) { $items = WC()->cart->get_cart(); $product_ids = array(); foreach($items as $item => $values) { $product_ids[] = $values[‘data’]->get_id(); //You can get product id of product added in cart } if(in_array($your_product_id, $product_ids)) // check whether your product is in cart $needs_shipping_address = true; return $needs_shipping_address; }

Remove Bulk Action For non admin user

Here’s how you can remove bulk actions for any user not an administrator. add_action( ‘wp_loaded’, ‘my_remove_bulk_actions’ ); function my_remove_bulk_actions() { if ( ! is_admin() ) return; if ( ! current_user_can( ‘administrator’ ) ) { add_filter( ‘bulk_actions-edit-shop_order’, ‘__return_empty_array’, 100 ); } } If you would like to target just the shop manager you can edit the … Read more

Woocommerce – exclude only older out-of-stock items

Most information necessary can be found at the Code Reference: WP_Query | Class . Otherwise useful resource Theme Handbook: Conditional Tags. Below code contains some clarifying comments. Please note, this is untested code, so no guarantees, but it should get you going. add_action( ‘woocommerce_product_query’, ‘custom_woocommerce_product_query’ ); function custom_woocommerce_product_query( $q ) { if ( ! is_admin() … Read more