Hide some items from Screen options in dashboard for products

The best option would be to use CSS to hide these columns and fields. Add this in your admin.css file to hide the SKU column table.wp-list-table .column-sku { width: 10% } To hide options in Screen Options add the following CSS in admin.css .metabox-prefs label:nth-child(2), .metabox-prefs label:nth-child(11), .metabox-prefs label:nth-child(12) { display: none; } FYI to … Read more

WooCommerce lost password reset flow not working with SendGrid (redirect loop)

If you’re using SendGrid to process emails from WooCommerce and have click tracking enabled, links that use $_GET vars will break. Sendgrid uses a URL sanitizer that converts the &id= to &id= and that creates an issue in WooCommerce… The password reset form redirect looks for two get vars, $_GET[‘key’] and $_GET[‘id’], and if they’re … Read more

Query multiple post type and categories

The following code selects IDs of all posts type product and post, which belong to terms category-a or category-b, with taxonomy_01 and taxonomy_02, respectively. $args = [ ‘post_type’ => [‘product’,’post’], ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘tax_query’ => [ ‘relation’ => ‘OR’, [ ‘taxonomy’ => ‘taxonomy_01’, ‘field’ => ‘slug’, ‘terms’ => ‘category-a’, ‘include_children’ => false, … Read more

Did I do it right? Deleting images after deleting product. Woocommerce

Looking at @obmerks answer on https://stackoverflow.com/questions/12997698/delete-images-after-post you can simplify it with this: foreach ( $productIds as $productId ) { $child_atts = $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE post_parent = $productId AND post_type=”attachment””); foreach ( $child_atts as $id ) wp_delete_attachment($id,true); } Note: as per documentation https://codex.wordpress.org/Function_Reference/wp_delete_attachment set the second parameter to true to force delete the attachment, … Read more

Show recent products first but “sold out last” in query

If we only have two stock statuses, namely outofstock and instock, we can very easily achieve sorting with pre_get_posts add_action( ‘pre_get_posts’, function ( $q ) { if ( !is_admin() // Target only front end && $q->is_main_query() // Only target the main query && $q->is_post_type_archive() // Change to suite your needs ) { $q->set( ‘meta_key’, ‘_stock_status’ … Read more

how to redirect to my template

Actually you can overwrite get_page_template() using page_template filter. So now, your code should be like bellow code. add_filter( ‘page_template’, ‘load_template_from_plugin’ ); function load_template_from_plugin( $page_template ){ if ( is_page( ‘bog_test’ ) ) { $page_template = dirname( __FILE__ ) . ‘/bog_test.php’; } return $page_template; } Try the above code then let me know the result. Thanks

Display Categories Assigned to a WooCommerce Product

I have solved the issue with creating a list with http://codex.wordpress.org/Template_Tags/wp_list_categories changing style to list, then style it with CSS to my needs 🙂 <?php $taxonomy = ‘product_cat’; // get the term IDs assigned to post. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( ‘fields’ => ‘ids’ ) ); if ( !empty( $post_terms ) && !is_wp_error( $post_terms … Read more