Skip to content

Instantly share code, notes, and snippets.

View dazecoop's full-sized avatar

Daze dazecoop

View GitHub Profile
@dazecoop
dazecoop / attributes-as-options.php
Last active April 16, 2024 02:57
WooCommerce product attributes as selectable options without variations
<?php
/**
* List available attributes on product page in a drop-down selection
*/
add_action('woocommerce_before_add_to_cart_button', 'list_attributes_on_product_page');
function list_attributes_on_product_page() {
global $product;
$attributes = $product->get_attributes();
@dazecoop
dazecoop / related-products-same-cat.php
Created April 24, 2020 19:20
In WooCommerce, only show products from same category within Related Products
@dazecoop
dazecoop / .htaccess
Created July 15, 2020 15:13
WordPress images on different domain
RewriteEngine On
RewriteCond %{HTTP_REFERER} !/wp-admin/ [NC]
RewriteRule ^(wp-content/uploads/.+?\.(jpe?g|png|gif|svg))$ https://domain.com/$1 [R=301,L]
@dazecoop
dazecoop / check-required-plugins.php
Last active July 21, 2020 20:53
Check specific WordPress plugins are activated, and alert if not
<?php
/**
* Check a list of plugins are activated, and alert if not.
* @param required_plugins[] should be updated to include the list of required plugins.
* @param `?show_active_plugins` can be appended to any URL within wp-admin to show a list of currently active plugins.
*/
class checkRequiredPlugin {
private $required_plugins = [
'woocommerce/woocommerce.php',
];
@dazecoop
dazecoop / output_json_phpunit.php
Created August 11, 2021 10:35
Output JSON from a $this->json() within Laravel/PHPUnit
$resp = $this->json('GET', "THE_URL", [
// THE PAYLOAD
]);
dd((array)json_decode($resp->content()));
@dazecoop
dazecoop / vue.config.js
Created October 24, 2021 16:00
Modify Vue default /dist output folder
module.exports = {
outputDir : 'public_html'
}
@dazecoop
dazecoop / cors.php
Created November 1, 2021 16:21
Basic PHP CORS
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
header('Access-Control-Allow-Headers: token, Content-Type');
header('Access-Control-Max-Age: 1728000');
header('Content-Length: 0');
header('Content-Type: text/plain');
die();
}
@dazecoop
dazecoop / README.md
Created November 10, 2021 10:19
Configure NPM to use different directory

Configure NPM to use different directory

Via stackoverflow and docs.npmjs.com


On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

echo '<pre style="white-space:normal; border:2px solid grey; margin:1rem; padding:1rem; font-size:12px;">';
print_r( vsprintf(str_replace(array('?'), array('\'%s\''), $query->toSql()), $query->getBindings()) );
echo '</pre>';
@dazecoop
dazecoop / README.md
Created January 26, 2022 13:39
Run temporary local PHP server on MacOS