Skip to content

Instantly share code, notes, and snippets.

View thagxt's full-sized avatar
🎯
Focusing

ʞↃ∀ɾ thagxt

🎯
Focusing
View GitHub Profile
@thagxt
thagxt / Get Author's name outside Loop in WordPress.php
Last active May 22, 2021 12:28
Get Author's name outside Loop in WordPress
<?php
global $post;
$author_id=$post->post_author;
?>
<?php
/* You can also use one of these instead:
- nickname
- user_nicename
- display_name
@thagxt
thagxt / Magento How to get the customer login, logout, register and checkout urls.php
Created April 23, 2014 12:10
Magento How to get the customer login, logout, register and checkout urls
login url
<?php echo Mage::getUrl('customer/account/login'); ?>
logout url
<?php echo Mage::getUrl('customer/account/logout'); ?>
My Account url
<?php echo Mage::getUrl('customer/account'); ?>
Register url
@thagxt
thagxt / dark-mode.js
Last active January 10, 2020 20:59
Detect if OS is in dark mode with Vanilla JS and add class to BODY
document.addEventListener("DOMContentLoaded", function(){
// Detect dark mode with Vanilla JS and add class to BODY
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add("dark-mode"); // your class here
}
// Turn Dark Mode on/off, manually
document.querySelector('.lightsoff').onclick = function() {
document.querySelector('body').classList.toggle('dark-mode');
}
@thagxt
thagxt / dark-mode.css
Last active October 27, 2019 12:17
Detect if the OS is in dark mode in browsers
/* Light mode */
@media (prefers-color-scheme: light) {
body {
background-color: #FFFFFF;
color: #000000;
}
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
@thagxt
thagxt / AJAX add to cart button on Shop page in WooCommerce.php
Created April 3, 2014 14:27
AJAX add to cart button on Shop page in WooCommerce
WTF: Get the AJAX add to cart button on Shop/Category/Search pages in WooCommerce. (AJAX works only for simple products)
HOW:
1) create a directory, name it "woocommerce" put it in your theme root.
2) copy/pasta from woocommerce plugin directory the content-product.php file
3) at the end of the (content-product.php) file, paste the code below:
<?php
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
@thagxt
thagxt / billing and shipping info in WooCommerce PDF Invoices & Packing Slips Invoice PDF separately.php
Last active March 4, 2019 23:36
Some times you feel the need to separate the billing info & shipping info you get in WooCommerce PDF Invoices & Packing Slips Invoice PDF file and get them one by one here's how to do it!
<?php
/*
* 1) open your invoice.php file
* 2) comment: // $wpo_wcpdf->billing_address();
* 3) copy/pasta: the first php block you see below
* 4) copy/pasta: the second php block remove what you don't need
* 5) save
* 6) go ham!
*/
?>
@thagxt
thagxt / get-product-info.php
Created August 25, 2016 14:10
Magento 2 > product page > get Product URL, get Product Name and get Product ID
<?php
// get current page URL
$URL = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
// get current product name & ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product
$id = $product->getId();
$title = $product->getName();
@thagxt
thagxt / How to Get the Base Url for a specific Magento Store View.php
Created April 23, 2014 12:25
How to Get the Base Url for a specific Magento Store View
<?php
/*
+ If you want, you can set manually the '$storeId' with the number (id) of the desired store.
+ You can also change 'Mage_Core_Model_Store::URL_TYPE_LINK' with one of these:
- Mage_Core_Model_Store::URL_TYPE_JS
- Mage_Core_Model_Store::URL_TYPE_LINK
- Mage_Core_Model_Store::URL_TYPE_MEDIA
- Mage_Core_Model_Store::URL_TYPE_SKIN
- Mage_Core_Model_Store::URL_TYPE_WEB
@thagxt
thagxt / functions.php
Created January 27, 2016 14:22
Function to add a class to all your "POST" images in WordPress and get them ready for lazyload.
<?php
function lazyload_filter_content($content) {
global $post; // getting The whole post objects
$content = $post->post_content;
if( is_singular() && is_main_query() ) {
//Renaming images for lazy loader!!!
@thagxt
thagxt / Add to cart button for Variables on Shop page in WooCommerce.php
Created April 3, 2014 14:28
Add to cart button for Variables on Shop page in WooCommerce
WTF: Get the add to cart button on Shop/Category/Search pages in WooCommerce. Not ajax version, works with Variable Products.
HOW:
1) create a directory, name it "woocommerce" put it in your theme root.
2) copy/pasta from woocommerce plugin directory the content-product.php file
3) at the end of the (content-product.php) file, paste the code below:
<?php do_action( 'woocommerce_single_product_summary' ); ?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>