Skip to content

Instantly share code, notes, and snippets.

@grola
grola / config.php
Last active Jan 21, 2018
Cloudflare Flexible SSL for Wordpress
View config.php
$https_options = array( 'HTTP_CF_VISITOR', 'HTTP_X_FORWARDED_PROTO' );
foreach ( $https_options as $https_option ) {
if ( isset( $_SERVER[ $https_option ] )
&& ( strpos( $_SERVER[ $https_option ], 'https' ) !== false )
) {
$_SERVER[ 'HTTPS' ] = 'on';
}
}
@grola
grola / functions.php
Created Jan 19, 2018
YOAST https:// cannonical URLs
View functions.php
function swp_wpseo_canonical_ssl( $url ) {
$url = str_replace( 'http://', 'https://', $url );
return $url;
}
add_filter( 'wpseo_canonical', 'swp_wpseo_canonical_ssl' );
@grola
grola / functions.php
Last active Jan 19, 2018
Leading zeros in WooCommerce order number
View functions.php
add_filter( 'woocommerce_order_number', 'swp_woocommerce_order_number_leading_zeros', 10 );
function swp_woocommerce_order_number_leading_zeros( $order_id ) {
$max_length = 8;
$new_order_id = str_pad( $order_id, $max_length, '0', STR_PAD_LEFT );
return $new_order_id;
}
@grola
grola / functions.php
Last active Jan 19, 2018
Shortcodes in Wordpress Text Widget
View functions.php
add_filter( 'widget_text', 'do_shortcode' );
@grola
grola / functions.php
Created Jan 20, 2018
Remove generator meta from header
View functions.php
remove_action('wp_head', 'wp_generator');
@grola
grola / functions.php
Last active Jan 22, 2018
Display WooCommerce variable product price
View functions.php
add_filter( 'woocommerce_variable_price_html', 'studiowp_woocommerce_variable_price_html', 10, 2 );
function studiowp_woocommerce_variable_price_html( $price, $product ) {
if ( !is_singular( 'product' ) ) {
$prices = $product->get_variation_prices( true );
if ( empty( $prices['price'] ) ) {
$price = apply_filters( 'woocommerce_variable_empty_price_html', '', $this );
} else {
$prefix = 'From ';
$suffix = '';
@grola
grola / functions.php
Last active Jan 28, 2018
Remove WooCommerce sorting options
View functions.php
<?php
$studiowp_remove_orderby = array( 'rating', 'popularity', 'price', 'price-desc' );
add_action( 'init', 'studiowp_init_orderby' );
function studiowp_init_orderby() {
global $studiowp_remove_orderby;
if ( !is_admin() && isset( $_GET['orderby'] ) ) {
if ( in_array( $_GET['orderby'], $studiowp_remove_orderby ) ) {
wp_redirect( home_url() );
@grola
grola / functions.php
Last active Jan 22, 2018
Variable product price
View functions.php
add_filter( 'woocommerce_variable_price_html', 'studiowp_woocommerce_variable_price_html', 10, 2 );
function studiowp_woocommerce_variable_price_html( $price, $product ) {
if ( !is_singular( 'product' ) ) {
$prices = $product->get_variation_prices( true );
if ( empty( $prices['price'] ) ) {
$price = apply_filters( 'woocommerce_variable_empty_price_html', '', $this );
} else {
$prefix = 'From ';
$suffix = '';
@grola
grola / functions.php
Last active Jan 23, 2018
Display additional content after "Add to cart" button on product page for declared categories
View functions.php
add_action( 'woocommerce_after_add_to_cart_button', 'studiowp_woocommerce_after_add_to_cart_button' );
function studiowp_woocommerce_after_add_to_cart_button() {
global $product;
$my_categories = array( 15, 16 );
$is_my_category = false;
$product_categories = $product->get_category_ids();
foreach ( $my_categories as $my_category ) {
if ( in_array( $my_category, $product_categories ) ) {
$is_my_category = true;
}
@grola
grola / functions.php
Created Jan 24, 2018
Remove downloads from My Account page in Woocommerce
View functions.php
add_action( 'woocommerce_account_menu_items', 'studiowp_woocommerce_account_menu_items' );
function studiowp_woocommerce_account_menu_items( $items ) {
unset( $items['downloads'] );
return $items;
}