Dropdown menu on custom page with product to choose number of products per page

Maybe this would work? function ps_pre_get_products_query( $query ) { $per_page = filter_input(INPUT_GET, ‘perpage’, FILTER_SANITIZE_NUMBER_INT); if ( ! is_admin() && is_woocommerce() && is_page() ) { $query->set( ‘posts_per_page’, $per_page ); } } I tested your code and the if statement didn’t seem to work with is_page() (but that could also be because my local WP sandbox is … Read more

Which hook should I use to capture $_POST(‘password’) via profile update and password reset

Sometimes you have to look at the name of the input you’re trying to pick up via $_POST. It’s not always consistent across forms. In the case of the WooCommerce password change form, the input name for the new password field is ‘password_1’ so that’s what you need to pick up via $_POST: function my_profile_update( … Read more

WooCommerce registration password field not displaying

To enable default Password field I just had to check checkbox (When creating an account, automatically generate an account password) under WooComemrce > Settings > Accounts and Privacy. After this default password field started to display on registration page. To add repeat password field I used this hook add_action( ‘woocommerce_register_form’, ‘wc_register_form_password_repeat’ ); function wc_register_form_password_repeat() { … Read more

How to hide out of stock products in Related Products via custom query in WooCommerce

Figured it out. None of the blog posts out there are accurate it seems. Put this in your functions.php file. You can change the posts per page number to see if its working straight away or not. add_filter( ‘woocommerce_output_related_products_args’, function( $args ) { $args = wp_parse_args( array( ‘posts_per_page’ => 4, ‘meta_query’ => array ( ‘key’ … Read more

Set a condition based on WooCommerce checkout city field while placing order

Updated The following code will add an additional recipient based on customer billing/shipping city, to new order admin notification: add_filter( ‘woocommerce_email_recipient_new_order’, ‘different_email_recipients’, 10, 2 ); function different_email_recipients( $recipient, $order ) { if ( ! is_a( $order, ‘WC_Order’ ) ) return $recipient; $city = $order->get_shipping_city(); $city = empty( $city ) ? $order->get_billing_city() : $city; // Conditionaly … Read more

Woocommerce redirect thankyou page based on product ID doesn’t empty Cart

Your actual code is a bit outdated and not so secure… Since WooCommerce 3 Order items are now Objects and $item[‘product_id’] is replaced by $item->get_product_id(). You should try first to use woocommerce_get_return_url like: add_action( ‘woocommerce_get_return_url’, ‘custom_order_received_return_url’, 10, 2 ); function custom_order_received_redirect( $return_url, $order ){ // HERE define your products IDs in the array $product_ids = … Read more

Custom Text in WooCommerce Order Processing Email Based on Products

Try something like this: <?php $order_id = $order->get_id(); $order = wc_get_order( $order_id ); $items = $order->get_items(); $is_valid = null; foreach ( $items as $item_id => $item_data ) { $product = $item_data->get_product(); $categories = array(); $terms = get_the_terms( $product->get_id(), ‘product_cat’ ); if ( is_wp_error( $terms ) || empty( $terms ) ) { continue; } foreach ( … Read more