Skip to content

Instantly share code, notes, and snippets.

View Jerl92's full-sized avatar

Jérémie Langevin Jerl92

View GitHub Profile
@Jerl92
Jerl92 / functions-admin.php
Last active February 16, 2018 17:43
Price based on user rôle / Back-end
<?php
add_action('woocommerce_product_options_general_product_data', 'woo_add_cost_price_field');
add_action('woocommerce_process_product_meta', 'woo_add_cost_price_field_save', 999);
function woo_add_cost_price_field(){
global $woocommerce, $post;
$post_id = $post->ID;
$calc_ = get_post_meta($post_id, '_wholesales_price', true) / 100 ;
$calc = $calc_ + 1;
echo '<div class="options_group">';
echo '</div>';
@Jerl92
Jerl92 / parallaxScroll.js
Created January 5, 2018 12:54
Parallax Scroll JS
jQuery(window).load(function() {
var theWindow = jQuery(window),
jQuerybg = jQuery(".custom-background"),
aspectRatio = jQuerybg.width() / jQuerybg.height();
function resizeBg() {
if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
jQuerybg
@Jerl92
Jerl92 / stock_report_csv.php
Created February 16, 2018 17:42
Stock Report Export to CSV
<?php
function generate_stock_report_csv() {
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
// set file name with current date
header('Content-Disposition: attachment; filename=endo-stock-report-' . date('Y-m-d') . '.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// set the column headers for the csv
$headings = array( 'Product' . '; ' . 'Stock' . '; ' . 'Price Cost' . '; ' . 'Price Cost All' . '; ' . 'Price' . '; ' . 'all price' );
@Jerl92
Jerl92 / example_widget.php
Created February 9, 2019 23:19
Wordpress template widget
<?php
/**
* Example Widget Class
*/
class example_widget extends WP_Widget {
/** constructor -- name this the same as the class above */
function example_widget() {
parent::WP_Widget(false, $name = 'Example Text Widget');
@Jerl92
Jerl92 / frontend-select-users.php
Created May 25, 2019 10:07
Show a selectable list of users
<?php
$users = get_users( array( 'fields' => array( 'ID' ) ) );
$html[] .= "<select id='event-users' multiple>";
foreach($users as $user_id){
if ( get_current_user_id() != $user_id->ID ) {
$data = get_user_meta ( $user_id->ID );
$html[] .= "<option value='$user_id->ID'>";
$html[] .= $user_id->ID;
$html[] .= " - ";
$html[] .= $data['first_name'][0];
@Jerl92
Jerl92 / events-page-template.php
Last active June 6, 2019 12:24
force use of templates from plugin folder
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $event_start_date = get_post_meta( get_the_ID(), '_event_start_date', true); ?>
<?php $event_end_date = get_post_meta( get_the_ID(), '_event_end_date', true); ?>
<div id="loop-container" class="loop-container">
@Jerl92
Jerl92 / custom-meta-boxes.php
Last active September 21, 2019 13:29
Wordpress Admin Custom Meta Boxes
<?php
function custom_meta_box_markup($object)
{
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
?>
<div>
<label for="meta-box-text">Text</label>
<input name="meta-box-text" type="text" value="<?php echo get_post_meta($object->ID, "meta-box-text", true); ?>">
@Jerl92
Jerl92 / woo_custom_product_tabs.php
Created September 26, 2021 00:57
woo_custom_product_tabs
<?php
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
function woo_custom_product_tabs( $tabs ) {
// 1) Removing tabs
// unset( $tabs['description'] ); // Remove the description tab
// unset( $tabs['reviews'] ); // Remove the reviews tab
// unset( $tabs['additional_information'] ); // Remove the additional information tab
@Jerl92
Jerl92 / download.php
Last active October 2, 2021 10:54
Stream video in header with direct path
<?php
$file = 'path/to/videofile.mp4';
$fp = @fopen($file, 'rb');
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
header("Content-Disposition: attachment; filename=\"{$fileName}\"");
@Jerl92
Jerl92 / Pagination.php
Last active June 27, 2023 05:00
Add Pagination in scandir()
<?php
$perpage = 10;
$page = (int)$_GET['page'];
if(!($page>0)) $page = 1;
$offset = ($page-1)*$perpage;
$extensions = array('3gp', 'mp4', 'png', 'gif', 'bmp');
$files = glob('files/'.$_GET['dir'].'/*.'.'{'.implode(',', $extensions).'}', GLOB_BRACE);
$total_files = sizeof($files);
$total_pages = ceil($total_files/$perpage);