Skip to content

Instantly share code, notes, and snippets.

View MrJoshFisher's full-sized avatar

Josh Fisher MrJoshFisher

View GitHub Profile
@MrJoshFisher
MrJoshFisher / Addto.phtml
Last active August 29, 2015 14:12
Magneto Disable Shopping Cart With Attribute
<?php
//Checks if the "Disable Add to Cart" variable is set to 'Yes':
if(($_product->getAttributeText('no_sample_button')) == "Yes"){
//If set to Yes, tell PHP what to output:
} else {
?>
@MrJoshFisher
MrJoshFisher / Show RRP Price & Sale Price In Cart
Created July 17, 2017 17:49
Shows the RRP Price / Sale Price on the cart page in the table.
add_filter( 'woocommerce_cart_item_price', 'bbloomer_change_cart_table_price_display', 30, 3 );
function bbloomer_change_cart_table_price_display( $price, $values, $cart_item_key ) {
$slashed_price = $values['data']->get_price_html();
$is_on_sale = $values['data']->is_on_sale();
if ( $is_on_sale ) {
$price = $slashed_price;
}
return $price;
}
@MrJoshFisher
MrJoshFisher / functions.php
Last active December 12, 2020 23:44
#WordPress Compression PHP - FLHM_HTML_Compression
class FLHM_HTML_Compression{
protected $flhm_compress_css = true;
protected $flhm_compress_js = true;
protected $flhm_info_comment = true;
protected $flhm_remove_comments = true;
protected $html;
public function __construct($html){
if (!empty($html)){
$this->flhm_parseHTML($html);
}
@MrJoshFisher
MrJoshFisher / bash.sh
Created December 12, 2020 23:46
[Bash Foreach] #bash
#!/bin/bash
FILES=*.flac
for f in $FILES
do
echo $f
ffmpeg -i "$f" "${f%%.*}.mp3"
done
@MrJoshFisher
MrJoshFisher / index.py
Created December 12, 2020 23:47
[Beautiful Soup] #bs4
#!/usr/bin/python
# Ratings Scraper
# Watches the house price on screetons.
from bs4 import BeautifulSoup
from datetime import datetime
import requests
import re
@MrJoshFisher
MrJoshFisher / index.py
Created December 12, 2020 23:48
[Selenium] #selenium
#!/usr/bin/python
import os
import urllib
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
@MrJoshFisher
MrJoshFisher / index.php
Created December 12, 2020 23:49
[ukvehicledata] UK Vehicle Data PHP Curl Example
<?php
$curl = curl_init();
$ApiKey = "<APIKEY>";
$postedcarreg = '<CARREG>';
$carreg = $postedcarreg;
$datatype = "VehicleData";
$url = "https://uk1.ukvehicledata.co.uk/api/datapackage/%s?v=2&api_nullitems=1&key_vrm=%s&auth_apikey=%s";
$url = sprintf($url, $datatype , $carreg, $ApiKey); // Syntax: sprintf($url, "PackageName", "VRM", ApiKey);
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
@MrJoshFisher
MrJoshFisher / .htacess
Created December 12, 2020 23:57
[Rewrite URLS to File] #htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
RewriteRule ^page-1$ page.php?area=1
RewriteRule ^page-2$ page.php?area=1
@MrJoshFisher
MrJoshFisher / single.php
Last active December 13, 2020 00:05
[Track WordPress Post Views by Using Post Meta] #WordPress
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}