Skip to content

Instantly share code, notes, and snippets.

Avatar
☣️
MASK ON

Jack Billström jackbillstrom

☣️
MASK ON
View GitHub Profile
@jackbillstrom
jackbillstrom / 1. wpFormsToDatalyer.js
Created Mar 1, 2021 — forked from kmclaugh/1. wpFormsToDatalyer.js
Notifies the datalyer when a wpForm is submitted so Google Tag Manager can detect it
View 1. wpFormsToDatalyer.js
// This code notifies Google Tag Manager when a wpForm is submitted
document.addEventListener("DOMContentLoaded", function() {
var elementsArray = document.querySelectorAll('[id^="wpforms-form-"]');
elementsArray.forEach(function(elem) {
elem.addEventListener("submit", function(e) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "wpFormSubmit",
wpFormElement: event.target
});
@jackbillstrom
jackbillstrom / wc_ajax_add_to_cart.php
Created Nov 18, 2020 — forked from adhershmnair/wc_ajax_add_to_cart.php
Woocommerce Ajax Add To Cart Button
View wc_ajax_add_to_cart.php
<?php
//AJAX ADD TO CART BUTTON
$product_id = 143;
if( !my_custom_cart_contains( $product_id ) ) {
?>
<button class="my-custom-add-to-cart-button" data-product-id="<?php echo $product_id; ?>">add to cart</button>
<?php
} else {
?>
View single.php
<?php
/**
* Simple product add to cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/simple.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
View cors-for-the-wordpress-rest-api.php
<?php
function my_customize_rest_cors() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: GET' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Expose-Headers: Link', false );
@jackbillstrom
jackbillstrom / command.sh
Last active Jul 21, 2020
How to renew a expired Let's Encrypt certificate via certbot
View command.sh
# This command will be generating a TXT-string you'll need to enter into your "_acme-challenge.example.se"
# When the new DNS post is live, you'll want to press ENTER in your shell to complete setup.
# My setup is a Debian machine with Apache as Web Server with virtualhosts.
sudo certbot-auto --server https://acme-v02.api.letsencrypt.org/directory -d "*.example.se" --preferred-challenges dns-01 certonly
View Option.php
<?
// /product-options-for-woocommerce/Model/Option.php
public function saveOptions($productId, $options) {
$productId = (int)$productId;
// Här kommer alla värden samlas upp efter loopen
// tänk på att loopen svarar RAD FÖR RAD
$lens_options = array();
@jackbillstrom
jackbillstrom / code.php
Created May 25, 2020
[WooCommerce] Recently Viewed Products
View code.php
/**
* goes inside your beloved functions.php
*/
add_shortcode( 'recently_viewed_products', 'code_recently_viewed_products' );
function code_recently_viewed_products() {
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) : array();
$viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
@jackbillstrom
jackbillstrom / [WP SSH SNIPPET] Skapa ny Wordpress på utv.miljö.md
Last active Jun 24, 2020
[WP SSH SNIPPET] Skapa ny Wordpress på utv.miljö
View [WP SSH SNIPPET] Skapa ny Wordpress på utv.miljö.md

[WP / SSH SNIPPET] Skapa ny Wordpress på utv.miljö

  • cd /var/www/
  • sudo mkdir -p subdomain/public_html
  • cd subdomain/pub*
  • sudo chown $USER:$USER -R .
  • wp core download
  • sudo chown www-data:www-data -R .

Importera från fil

@jackbillstrom
jackbillstrom / index.html
Created May 10, 2020
tailwind-landing-page
View index.html
<body
class="text-gray-700 bg-white"
style="font-family: 'Source Sans Pro', sans-serif"
>
<!--Nav-->
<nav>
<div
class="container mx-auto px-6 py-2 flex justify-between items-center"
>
<a class="font-bold text-2xl lg:text-4xl" href="#">