Skip to content

Instantly share code, notes, and snippets.

View Basilakis's full-sized avatar
🏠
Working from home

Basilis Kanonidis Basilakis

🏠
Working from home
View GitHub Profile
@Basilakis
Basilakis / dynamic-fees.php
Last active March 27, 2018 15:24
Dynamic Fees for Shipping Per Payment GateWay for WooCommerce
add_action('init', 'cg_init');
function cg_init() {
add_action('woocommerce_cart_calculate_fees', 'cg_add_fee');
add_action('wp_footer', 'cg_footer', 9999);
}
function cg_footer() {
?>
<script type="text/javascript">
@Basilakis
Basilakis / eventon-custom-field.php
Created February 11, 2018 15:36
eventON Custom Field Functionality
<?php
/*
Plugin Name: eventON single custom field
Plugin URI: https://eventon.com
Description: A text field for eventON submit event form
Author: Basilis Kanonidis
Version: 2.0
License: GPLv2 or later
*/
@Basilakis
Basilakis / hextorgba.php
Created December 26, 2017 16:23
Convert HEX value to RGBA
function mk_convert_rgba($colour, $alpha)
{
if (!empty($colour)) {
if ($alpha >= 0.95) {
return $colour; // If alpha is equal 1 no need to convert to RGBA, so we are ok with it. :)
} else {
if ($colour[0] == '#') {
$colour = substr($colour, 1);
}
if (strlen($colour) == 6) {
@Basilakis
Basilakis / edd-shortcodes.php
Created November 13, 2017 13:11
Easy Digital Download Shortcoddes for Open Metrics
// Avg downloads per customer
function sc_edd_avg_downloads_per_customer( $atts ) {
$amount = 0;
$query = new WP_Query( array( 'post_type' => 'download' ) );
foreach( $query->posts as $post ) {
$amount = $amount + edd_get_download_sales_stats( $post->ID );
}
$amount = $amount / edd_count_total_customers();
return number_format( $amount, 2 );
}
@Basilakis
Basilakis / search.php
Created October 10, 2017 19:10
Make search work only on one category
<form class="mk-searchform" method="get" id="searchform" action="<?php echo home_url(); ?>">
<input type="text" class="text-input" value="<?php if(!empty($_GET['s'])) echo get_search_query(); ?>" name="s" id="s" />
<input type="hidden" value="59" name="cat" id="scat" />
<i class="mk-icon-search"><input value="" type="submit" class="search-button" type="submit" /></i>
</form>
@Basilakis
Basilakis / plugin.php
Created October 7, 2017 15:31
Make customers vendors FES
<?php
add_action( 'edd_complete_purchase', 'fes_add_buyers_as_vendors', 10, 1 );
function fes_add_buyers_as_vendors( $payment_id ){
$customer_id = edd_get_payment_customer_id( $payment_id );
$db_user = new FES_DB_Vendors();
if ( $db_user->exists( 'id', $customer_id ) {
return;
}
@Basilakis
Basilakis / mediaquery.css
Last active August 15, 2017 15:38
Responsive Sizes
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}
@Basilakis
Basilakis / functions.php
Created July 31, 2017 13:16
Adds a class of "wp_is_mobile" to the body class of the page
function add_is_mobile_bodyclass($classes) {
//adds a class of "wp_is_mobile" to the body class of the page
if (wp_is_mobile()) {
$classes[] = 'wp_is_mobile';
}
return $classes;
}
add_filter('body_class','add_is_mobile_bodyclass');
@Basilakis
Basilakis / custom_wp_is_mobile.php
Created July 30, 2017 19:36 — forked from sachyya/custom_wp_is_mobile.php
This gist is to use WordPress inbuilt function wp_is_mobile excluding the ipad view port
function custom_wp_is_mobile() {
static $is_mobile;
if ( isset($is_mobile) )
return $is_mobile;
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
$is_mobile = false;
} elseif (
strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
@Basilakis
Basilakis / functions.php
Last active February 7, 2017 16:58
Redirect log - out users from Custom Post Type Singular
function logedout_singular_redirect() {
if (!is_user_logged_in() && ( is_singular( 'job_listing' ) )
) {
// feel free to customize the following line to suit your needs
wp_redirect(site_url('my-page-slug/'));
exit;
}
}
add_action('template_redirect', 'logedout_singular_redirect');