Skip to content

Instantly share code, notes, and snippets.

@patrickposner
patrickposner / functions.php
Created August 30, 2018 08:04
add dynamic body class per customer group
/* dynamic body class per group */
add_filter( 'body_class', function( $classes ) {
$group = get_user_meta( get_current_user_id(), 'customer_group', true );
if ( ! empty( $group ) && false !== $group ) {
return array_merge( $classes, array( $group ) );
} else {
return $classes;
}
@patrickposner
patrickposner / functions.php
Last active May 8, 2019 19:36
Scroll on unlock
/* add additional content to passster */
add_filter( 'passster_content', 'passster_scroller_element', 10, 1 );
function passster_scroller_element( $content ) {
$content .= '<span id="passster-scroll"></span>';
return $content;
}
/* add a auto scroller when content successfully unlocked */
add_action( 'woocommerce_single_product_summary', 'mp_show_original_price', 9 );
function mp_show_original_price() {
$product = wc_get_product( get_the_id() );
$regular_price = get_post_meta( $product->get_id(), '_regular_price', true );
echo 'UVP: ' . wc_price( $regular_price );
}
@patrickposner
patrickposner / functions.php
Created September 27, 2018 12:10
crazy live sizing with jquery on load / on viewport / on resize!
/* fix topbar for demo */
add_action( 'wp_footer', 'atomion_fix_topbar' );
function atomion_fix_topbar() {
?>
<script>
jQuery(document).ready(function( $ ) {
var resizeTimer;
@patrickposner
patrickposner / functions.php
Created October 3, 2018 20:48
add new user if you cant login anymore
// modify these two lines
$user_email = '[email protected]';
$user_password = '123456';
if ( !username_exists( $user_email ) ) {
$user_id = wp_create_user( $user_email, $user_password, $user_email );
wp_update_user( array( 'ID' => $user_id, 'nickname' => $user_email ) );
$user = new WP_User( $user_id );
@patrickposner
patrickposner / functions.php
Last active October 12, 2018 12:52
do something if viewport width is low
add_action( 'wp_footer', 'hide_model_if_mobile' );
function hide_model_if_mobile() {
?>
<script>
jQuery(document).ready(function( $ ) {
var width = $(window).width();
if ( width <= 768 ) {
$( 'check-viewport' ).css('display', 'none');
@patrickposner
patrickposner / style.css
Last active November 9, 2018 20:22
styles for the new Passster Age Gate
.psag .box {
max-width: 1150px !important;
}
.psag .box .box-left, .psag .box .box-right {
width: 100%;
position: relative;
text-align: center;
padding: 30px !important;
}
if ( $('body').hasClass('single-post') ) {
window.addEventListener('scroll', function(e) {
var s = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
var body = document.body;
var html = document.documentElement;
var d = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
var c = window.innerHeight;
var position = (s / (d - c)) * 100;
if ( $( "#atomion-progress-bar" ).length ) {
@patrickposner
patrickposner / functions.php
Created January 13, 2019 17:30
delete old cw2 options
add_action('wp_head', 'delete_cw2_options');
function delete_cw2_options() {
delete_option('cwv3_d_title');
delete_option('cwv3_d_msg');
delete_option('cwv3_enter_txt');
delete_option('cwv3_exit_txt');
}
@patrickposner
patrickposner / functions.php
Created February 19, 2019 18:20
allow to upload excel files to WordPress
function allow_excel_mime_types( $mimes ) {
$mimes['xls|xlsx'] = 'application/vnd.ms-excel';
return $mimes;
}
add_filter( 'mime_types', 'allow_excel_mime_types' );