add_action( 'woocommerce_before_cart', 'shipjar_apply_coupon_number_of_products' );
function shipjar_apply_coupon_number_of_products() {
$coupon_code = 'snipdeal';
// if there are more than 5 different products in the cart
if( 5 < count( WC()->cart->get_cart() ) ) {
if( ! WC()->cart->has_discount( $coupon_code ) ) {
WC()->cart->apply_coupon( $coupon_code );
}
} else {
WC()->cart->remove_coupon( $coupon_code );
WC()->cart->calculate_totals();
}
}
Apply a coupon if there is a specific product in cart
When a customer purchases a specific product you may want to provide a specific discount to all the products in the cart automatically.
add_action( 'woocommerce_before_cart', 'snipjar_apply_coupon_specific_product' );
function snipjar_apply_coupon_specific_product() {
$coupon_code = 'snipdeal';
$product_id = 678;
// if product in the cart
if( in_array( $product_id, array_column( WC()->cart->get_cart(), 'product_id' ) ) ) {
if( ! WC()->cart->has_discount( $coupon_code ) ) {
WC()->cart->apply_coupon( $coupon_code );
}
} else { // if product removed from cart we remove the coupon
WC()->cart->remove_coupon( $coupon_code );
WC()->cart->calculate_totals();
}
}
Disable Plugin & Theme file editor
// Disable the Plugin and Theme Editor
if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) {
define( 'DISALLOW_FILE_EDIT', true );
}
Disable admin email confirmation screen
Prevent WordPress from requesting confirmation of the administrator email address upon login.
add_filter( 'admin_email_check_interval', '__return_false' );
Disable user password reset notification email
After a user resets their password, do not send the notification email to the site administrator.
remove_action( 'after_password_reset', 'wp_password_change_notification' );
Move admin bar to the bottom
body {margin-top: -28px;padding-bottom: 28px;}
body.admin-bar #wphead {padding-top: 0;}
body.admin-bar #footer {padding-bottom: 28px;}
#wpadminbar { top: auto !important;bottom: 0;}
#wpadminbar .menupop .ab-sub-wrapper { bottom: 32px; }
Add custom CSS in the Admin dashboard
Add custom CSS in the WordPress admin head. Add the CSS code between the style tags.
add_action( 'admin_head', function() {
?>
<style>
</style>
<?php
} );
Change “Add to cart” text
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
if ( 'Add to cart' == $text ) {
$text = __( 'Buy Now', 'woocommerce' );
}
return $text;
} );
Disable automatically deleting trashed posts
Do not let WordPress delete trashed posts after 30 days.
add_action( 'init', function() {
remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
} );
Change excerpt length
add_filter(
'excerpt_length',
function ( $length ) {
// Number of words to display in the excerpt.
return 40;
},
500
);
Remove Gutenberg Block Library CSS from loading on the frontend
function smartwp_remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
}
add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css' );
Open all external links in new tab
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($) {
$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});
});
//]]>
</script>