-
How to change WooCommerce Products post type name
add_filter( ‘woocommerce_register_post_type_product’, ‘so_26712459_post_type’ ); function so_26712459_post_type( $args ){ $labels = array( ‘name’ => __( ‘Tours’, ‘your-custom-plugin’ ), ‘singular_name’ => __( ‘Tour’, ‘your-custom-plugin’ ), ‘menu_name’ => _x( ‘Tours’, ‘Admin menu name’, ‘your-custom-plugin’ ), ‘add_new’ => __( ‘Add Tour’, ‘your-custom-plugin’ ), ‘add_new_item’ => __( ‘Add New Tour’, ‘your-custom-plugin’ ), ‘edit’ => __( ‘Edit’, ‘your-custom-plugin’ ), ‘edit_item’ => __( ‘Edit Tour’, ‘your-custom-plugin’ ), ‘new_item’ => __( ‘New Tour’, ‘your-custom-plugin’ ), ‘view’ => __( ‘View Tour’, ‘your-custom-plugin’ ), ‘view_item’ => __( ‘View Tour’, ‘your-custom-plugin’ ), ‘search_items’ => __( ‘Search Tours’, ‘your-custom-plugin’ ), ‘not_found’ => __( ‘No Tours found’, ‘your-custom-plugin’ ), ‘not_found_in_trash’ => __( ‘No Tours found in trash’, ‘your-custom-plugin’ ), ‘parent’ => __( ‘Parent […]
-
Override translations
Override “Add to Cart” etc for virtual products in WooCommerce <?php add_filter( ‘gettext’, ‘studio_gettext’, 10, 3); function studio_gettext( $translation, $text, $domain ) { if ( ‘woocommerce’ === $domain ) { global $product; if ( ‘%s in stock’ === $text && $product->is_virtual() ){ $translation = ‘Available %s persons’; } if ( ‘Add to cart’ === $text && $product->is_virtual() ){ $translation = ‘Sign up’; } } return $translation; } ?>
-
Contact Form 7 change text of select include_blank
/** * Customize the default option selected on CF7 */</span> <span class=”hljs-function”><span class=”hljs-keyword”>function</span> <span class=”hljs-title”>my_wpcf7_form_elements</span>(<span class=”hljs-params”>$html</span>) </span>{ $text = <span class=”hljs-string”>’β'</span>; $html = str_replace(<span class=”hljs-string”>’—‘</span>, $text , $html); <span class=”hljs-keyword”>return</span> $html; } add_filter(<span class=”hljs-string”>’wpcf7_form_elements'</span>, <span class=”hljs-string”>’my_wpcf7_form_elements'</span>); Source: https://stackoverflow.com/questions/26902160/contact-form-7-default-option-print-as-selected-value-in-mail
-
Disable WordPress update notification
// hide update notifications function remove_core_updates(){ global $wp_version;return(object) array(‘last_checked’=> time(),’version_checked’=> $wp_version,); } add_filter(‘pre_site_transient_update_core’,’remove_core_updates’); //hide updates for WordPress itself add_filter(‘pre_site_transient_update_plugins’,’remove_core_updates’); //hide updates for all plugins add_filter(‘pre_site_transient_update_themes’,’remove_core_updates’); //hide updates for all themes Reference: https://thomas.vanhoutte.be/miniblog/wordpress-hide-update/
-
Making the Quantity Field a Dropdown in WooCommerce
https://aceplugins.com/making-the-quantity-field-a-dropdown-in-woocommerce/
-
Allow shortcodes in widgets
add_filter( ‘widget_text’, ‘do_shortcode’ );
-
How to override an image size in WooCommerce
Product single <?php add_filter( ‘woocommerce_get_image_size_single’, function( $size ) { return array( ‘width’ => 400, ‘height’ => ”, ‘crop’ => 0, ); } ); add_filter( ‘woocommerce_get_image_size_single’, function( $size ) { return array( ‘width’ => 500, ‘height’ => 500, ‘crop’ => 1, ); } ); Thumbnail (for shop and category pages) add_filter( ‘woocommerce_get_image_size_thumbnail’, function( $size ) { return array( ‘width’ => 500, ‘height’ => 500, ‘crop’ => 1, ); } ); Gallery add_filter( ‘woocommerce_get_image_size_gallery_thumbnail’, function( $size ) { return array( ‘width’ => 400, ‘height’ => 400, ‘crop’ => 1, ); } );
-
Debugging WP Mail
// define the wp_mail_failed callback function action_wp_mail_failed($wp_error) { return error_log(print_r($wp_error, true)); } // add the action add_action(‘wp_mail_failed’, ‘action_wp_mail_failed’, 10, 1); I personally use slack’s webhooks and other methods for this notification. Reference: https://www.codeforest.net/debugging-wp-mail-like-a-boss-debugger
-
Add styles to wp-admin
use the admin_head hook add_action(‘admin_head’, ‘my_admin_style’); function my_custom_fonts() { ?> <style> tr[data-gateway_id^=”stripe_”] { display: none; } </style> <?php } or, you can use the admin_enqueue_scripts hook add_action(‘admin_enqueue_scripts’, ‘my_admin_stylesheet’); function my_admin_stylesheet() { // enqueue your stylesheet wp_enqueue_script( ‘my_custom_script’, plugin_dir_url( __FILE__ ) . ‘myscript.js’, array(), ‘1.0’ ); }
-
Show Variations on the Shop Page
/** * Replace add to cart button in the loop. */ function iconic_change_loop_add_to_cart() { remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 ); add_action( ‘woocommerce_after_shop_loop_item’, ‘iconic_template_loop_add_to_cart’, 10 ); } add_action( ‘init’, ‘iconic_change_loop_add_to_cart’, 10 ); /** * Use single add to cart button for variable products. */ function iconic_template_loop_add_to_cart() { global $product; if ( ! $product->is_type( ‘variable’ ) ) { woocommerce_template_loop_add_to_cart(); return; } remove_action( ‘woocommerce_single_variation’, ‘woocommerce_single_variation_add_to_cart_button’, 20 ); add_action( ‘woocommerce_single_variation’, ‘iconic_loop_variation_add_to_cart_button’, 20 ); woocommerce_template_single_add_to_cart(); } /** * Customise variable add to cart button for loop. * * Remove qty selector and simplify. */ function iconic_loop_variation_add_to_cart_button() { global $product; ?> <div class=”woocommerce-variation-add-to-cart variations_button”> <button type=”submit” class=”single_add_to_cart_button button”><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button> <input type=”hidden” name=”add-to-cart” value=”<?php […]