Skip to content

Instantly share code, notes, and snippets.

@rad73
rad73 / WooCommerce: Place Out of Stock Last in the Loop
Created October 14, 2018 21:01
WooCommerce: Place Out of Stock Last in the Loop
add_filter('posts_clauses', 'loc_order_by_stock_status');
function loc_order_by_stock_status($posts_clauses) {
global $wpdb;
if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag())) {
$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
$posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
$posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
}
return $posts_clauses;
}
@rad73
rad73 / WordPress: Translates login page labels
Created October 14, 2018 21:01
WordPress: Translates login page labels
function loc_translate_login_username() {
function loc_login_label_username( $translated_text, $text, $domain ) {
if ( 'Username or Email Address' === $text || 'Username' === $text ) {
$translated_text = __( 'User ID' , 'flatsome-child' );
}
return $translated_text;
}
add_filter( 'gettext', 'loc_login_label_username', 20, 3 );
}
add_action( 'login_head', 'loc_translate_login_username' );
@rad73
rad73 / WordPress: "Last Updated on" for posts
Created October 14, 2018 21:00
WordPress: "Last Updated on" for posts
function loc_article_update_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i');
$custom_content .= '<p class="last-updated">Updated on '. $updated_date . ' at '. $updated_time .'</p>';
// feel free to change the text printed on line 7 into whatever you like
}
@rad73
rad73 / WooCommerce: Product Inquiry Form @ Product Page
Created October 14, 2018 20:59
WooCommerce: Product Inquiry Form @ Product Page
add_action( 'woocommerce_single_product_summary', 'request_qoute', 30 );
function request_qoute() {
echo '<button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt">Request a Quote</button>';
echo '<div id="product_inq" style="display:none">';
echo do_shortcode('[paste_your_contact_form_7_shortcode_here]');
echo '</div>';
}
add_action( 'woocommerce_single_product_summary', 'show_and_hide_quote', 40);
function show_and_hide_quote() {
@rad73
rad73 / WooCommerce: Product Bulk or Inquiry Form
Created October 14, 2018 20:57
WooCommerce: Product Bulk / Inquiry Form
// The form will automatically fetch information from the product (only single products)
// and put that information into a CF7 form.
// 1) Make sure you have Contact Form 7 installed
// 2) Install "Contact Form 7 - Dynamic Text Extension"
// Link: https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/
// Form section for your CF7 ->
<div class="locfix">
<div id="left">
@rad73
rad73 / WooCommerce: Product Inquiry on Product Description
Created October 14, 2018 20:57
WooCommerce: Product Inquiry on Product Description
function loc_product_inquiry_cf7() {
echo '<button type="submit" id="trigger_inquiry" class="single_add_to_cart_button button alt">Product Inquiry</button>';
echo '<div id="product_inquiry" style="display:none">';
echo do_shortcode('[INSERT YOUR CONTACT FORM 7 SHORTCODE HERE]');
echo '</div>';
}
add_action( 'woocommerce_single_product_summary', 'loc_product_inquiry_cf7', 30 );
function loc_product_inquiry_cf7_populate() {
?>
@rad73
rad73 / Web Server: Vary: Accept-Encoding
Created October 14, 2018 20:56
Web Server: Vary: Accept-Encoding
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
// To fix this on a NGINX server configuration, use this: gzip_vary on
// The NGINX configuration files are located in /etc/nginx/ and the primary configuration file is /etc/nginx/nginx.conf.
@rad73
rad73 / HTML, CSS & JS: Picture slideshow
Created October 14, 2018 20:55
HTML, CSS & JS: Picture slideshow
Slideshow ->
<div class="slideshow bb-display-container bb-center">
<img src="/images/la.jpg" style="width:100%">
<div class="bb-display-bottommiddle bb-container bb-text-white bb-padding-32 bb-hide-small">
<h3>Los Angeles</h3>
<p><b>We had the best time playing at Venice Beach!</b></p>
</div>
</div>
<div class="slideshow bb-display-container bb-center">
@rad73
rad73 / HTML, CSS & JS: Coming Soon (Under Construction)
Created October 14, 2018 20:55
HTML, CSS & JS: Coming Soon (Under Construction)
// step 1 is to add the code below to your .htaccess file. Make sure to change the IP number to your own.
// This means that everyone except you (your IP) will be re-directed to the "Coming soon" page.
// If you remove line 10 the background will not work.
# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/comingsoon.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
@rad73
rad73 / .htaccess: How to force SSL
Created October 14, 2018 20:55
.htaccess: How to force SSL
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]