-
WordPress resize Image after Upload
https://blog.nicohood.de/wordpress-resize-image-after-upload
-
Automatically complete orders in WooCommerce
add_action( ‘woocommerce_order_status_processing’, ‘custom_autocomplete_order’ ); function custom_autocomplete_order( $order_id ) { if ( ! $order_id ) { return; } $order = wc_get_order( $order_id ); // get status $status = $order->get_status(); if( $status == ‘processing’) $order->update_status( ‘completed’ ); } https://usersinsights.com/woocommerce-automatically-complete-orders/
-
WooCommerce filter product by price
add_filter( ‘woocommerce_product_data_store_cpt_get_products_query’, ‘handle_price_range_query_var’, 10, 2 ); function handle_price_range_query_var( $query, $query_vars ) { if ( ! empty( $query_vars[‘price_range’] ) ) { $price_range = explode( ‘|’, esc_attr($query_vars[‘price_range’]) ); if ( is_array($price_range) && count($price_range) == 2 ) { $query[‘meta_query’][‘relation’] = ‘AND’; $query[‘meta_query’][] = array( ‘key’ => ‘_price’, ‘value’ => reset($price_range), // From price value ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ); if( end($price_range) != ”){ $query[‘meta_query’][] = array( ‘key’ => ‘_price’, ‘value’ => end($price_range), // To price value ‘compare’ => ‘<=’, ‘type’ => ‘NUMERIC’ ); } $query[‘orderby’] = ‘meta_value_num’; // sort by price $query[‘order’] = ‘ASC’; // In ascending order } } return $query; } thanks to https://stackoverflow.com/questions/66072017/filter-products-by-price-range-using-woocommerce-wc-get-products
-
Remove image sizes
add_filter( ‘intermediate_image_sizes_advanced’, ‘hoge_remove_default_images’ ); function hoge_remove_default_images( $sizes ) { unset( $sizes[‘small’]); // 150px unset( $sizes[‘medium’]); // 300px unset( $sizes[‘large’]); // 1024px unset( $sizes[‘medium_large’]); // 768px return $sizes; }
-
Display EXIF and IPTC Metadata in the Edit Media Screen
function media_hacks_attachment_fields_to_edit( $form_fields, $post ){ // get post mime type $type = get_post_mime_type( $post->ID ); // get the attachment path $attachment_path = get_attached_file( $post->ID ); // get image metadata $metadata = wp_read_image_metadata( $attachment_path ); if( ‘image/jpeg’ == $type ){ if( $metadata ) { $exif_data = array( ‘aperture’ => ‘Aperture’, ‘camera’ => ‘Camera’, ‘created_timestamp’ => ‘Timestamp’, ‘focal_length’ => ‘Focal Length’, ‘iso’ => ‘ISO’, ‘shutter_speed’ => ‘Exposure Time’, ‘orientation’ => ‘Orientation’ ); foreach ( $exif_data as $key => $value ) { $exif = $metadata[$key]; $form_fields[$key] = array( ‘value’ => $exif ? $exif : ”, ‘label’ => __( $value ), ‘input’ => ‘html’, ‘html’ => “ID][$exif]’ value='” . $exif . “‘ /> ); […]
-
How to customize the Add to Cart button in WooCommerce
https://quadlayers.com/customize-add-to-cart-button-woocommerce/
-
Override loop template and show quantities next to add to cart buttons
/** * Override loop template and show quantities next to add to cart buttons */ add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘quantity_inputs_for_woocommerce_loop_add_to_cart_link’, 10, 2 ); function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) { if ( $product && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) { $html = ‘<form action=”‘ . esc_url( $product->add_to_cart_url() ) . ‘” class=”cart” method=”post” enctype=”multipart/form-data”>’; $html .= woocommerce_quantity_input( array(), $product, false ); $html .= ‘<button type=”submit” class=”button alt”>’ . esc_html( $product->add_to_cart_text() ) . ‘</button>’; $html .= ‘</form>’; } return $html; } https://woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/
-
How to add defer / async in wp_enqueue_script
To add defer / async to enqueued script with id “fontawesome5 <?php wp_enqueue_script(‘fontawesome5’, ‘https://use.fontawesome.com/releases/v5.0.9/js/all.js’, array(), ‘5.0.9’, true); <?php add_filter(‘script_loader_tag’, ‘add_defer’, 10, 2); function add_defer($tag, $handle) { if($handle !== ‘fontawesome5’) { return $tag; } return str_replace(‘ src=’, ‘ defer src=’, $tag); } <?php add_filter(‘script_loader_tag’, ‘add_async’, 10, 2); function add_async($tag, $handle) { if($handle !== ‘fontawesome5’) { return $tag; } return str_replace(‘ src=’, ‘ async src=’, $tag); } Source: https://e-joint.jp/505/
-
Customize new user notification email
add_filter( ‘wp_new_user_notification_email’, ‘custom_wp_new_user_notification_email’, 10, 3 ); function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) { $key = get_password_reset_key( $user ); $message = sprintf(__(‘Welcome to the Community,’)) . “\r\n\r\n”; $message .= ‘To set your password, visit the following address:’ . “\r\n\r\n”; $message .= network_site_url(“wp-login.php?action=rp&key=$key&login=” . rawurlencode($user->user_login), ‘login’) . “\r\n\r\n”; $message .= “After this you can enjoy our website!” . “\r\n\r\n”; $message .= “Kind regards,” . “\r\n”; $message .= “Support Office Team” . “\r\n”; $wp_new_user_notification_email[‘message’] = $message; $wp_new_user_notification_email[‘headers’] = ‘From: MyName<example@domain.ext>’; // this just changes the sender name and email to whatever you want (instead of the default WordPress <wordpress@domain.ext> return $wp_new_user_notification_email; } https://wordpress.stackexchange.com/questions/306642/customize-wp-new-user-notification-email
-
How to Hide ‘Add to Cart’ Button in WooCommerce
add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’); Source: https://wisdmlabs.com/blog/the-right-way-to-hide-add-to-cart-button-in-woocommerce/