Remove child products from woocommerce category page [closed]

you want to display only parent category products and remove the child category products. Add the following lines of code at the end of your theme’s functions.php file. function exclude_product_cat_children( $wp_query ) { if ( isset( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query() ) { $wp_query->set( ‘tax_query’, array( array ( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => … Read more

How to solve suspected memory issue in custom WordPress loop?

There are approx. 10,000 items returned by the query. That’s your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( ‘fields’ => ‘ids’, // MAGIC! Just get an array … Read more

Programmatically change Payment Methods WooCommerce

Theres a filter called woocommerce_available_payment_gateways: add_filter(‘woocommerce_available_payment_gateways’,’filter_gateways’,1); function filter_gateways($gateways){ global $woocommerce; //Remove a specific payment option unset($gateways[‘paypal’]); return $gateways; } I’m not sure where and how you get / store the Request for Quote option, but you can access the value inside the filter_gateways function and you can remove a specific gateway with a conditional logic.

Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out

It seems that the OP have managed to solve his/her problem by doing this, which can be found at Different menus for logged-in users. if ( is_user_logged_in() ) { wp_nav_menu( array( ‘theme_location’ => ‘logged-in-menu’ ) ); } else { wp_nav_menu( array( ‘theme_location’ => ‘logged-out-menu’ ) ); } The more shorter way to achieve that is … Read more

Permalinks for WooCommerce Categories and Subcategories

I was able to resolve this with the following code which generates rewrite_rules for each subcategory, which is preferred during matching since it’s more specific: function wpse_291143_generate_taxonomy_rewrite_rules( $wp_rewrite ) { global $wp_rewrite; $base = “shop”; $rules = array(); $terms = get_terms( array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false )); foreach($terms as $term) { $term_children = … Read more

When Free shipping is available hide other shipping methods except Local pickup in WooCommerce [closed]

The following code will disable other shipping methods excluding “Local Pickup” when “Free shipping” shipping method is available. Required: Free shipping method need to be set with a minimal order amount. add_filter( ‘woocommerce_package_rates’, ‘show_hide_shipping_methods’, 100 ); function show_hide_shipping_methods( $rates ) { $free_rate_id = ”; $other_rates_ids = []; // Loop through available shipping rates foreach ( … Read more

pagination in woocommerce order history page

I have added pagination in order history page and it is working. Replace below code above loop $customer_orders1 = get_posts(apply_filters(‘woocommerce_my_account_my_orders_query’, array( ‘numberposts’ => -1, ‘meta_key’ => ‘_customer_user’, ‘meta_value’ => get_current_user_id(), ‘post_type’ => wc_get_order_types(‘view-orders’), ‘post_status’ => array_keys(wc_get_order_statuses()) ))); $total_records = count($customer_orders1); $posts_per_page = 20; $total_pages = ceil($total_records / $posts_per_page); $paged = ( get_query_var(‘page’) ) ? get_query_var(‘page’) … Read more

WP_Query | Help me create a search term with an ‘OR’ relation?

(Revised on March 25 2020 UTC) So in this revised answer, I’ll just begin with the code: Define the variables: (I intentionally included only the $args part) // define POSTed/submitted variables here like $paged, $display_count and $direction // define the offset/’direction’ stuff here // then define your $args array $args = array( ‘post_type’ => ‘product’, … Read more

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