Using Cookie Data For WP_Query Loop

You need to explode the comma separated string to get the array of IDs. Follow the below code. $cookie_array = $_COOKIE[“your-results”]; // Test output echo $cookie_array; $cookie_array = array_map( ‘absint’, (array) explode(‘,’, $cookie_array) ); $sug_args = array( ‘post_type’ => ‘product’, ‘post__in’ => $cookie_array, ); $sug_query = new WP_query ($sug_args); if( $sug_query->have_posts() ) : while( $sug_query->have_posts() … Read more

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