Skip to content

Instantly share code, notes, and snippets.

View web-hat's full-sized avatar

WebHat web-hat

View GitHub Profile
SELECT p.`ID` AS 'Product ID',
p.`post_title` AS 'Product Name',
t.`term_id` AS 'Attribute Value ID',
REPLACE(REPLACE(tt.`taxonomy`, 'pa_', ''), '-', ' ') AS 'Attribute Name',
t.`name` AS 'Attribute Value'
FROM `wp_posts` AS p
INNER JOIN `wp_term_relationships` AS tr ON p.`ID` = tr.`object_id`
INNER JOIN `wp_term_taxonomy` AS tt ON tr.`term_taxonomy_id` = tt.`term_id`
AND tt.`taxonomy` LIKE 'pa_%'
INNER JOIN `wp_terms` AS t ON tr.`term_taxonomy_id` = t.`term_id`
@web-hat
web-hat / custom_field_admin_screen.php
Last active September 21, 2019 21:56
Populating custom fields value in product categories admin screen or in categories listing table.
<?php
//Displaying Additional Columns
add_filter( 'manage_edit-product_cat_columns', 'wh_customFieldsListTitle' ); //Register Function
add_action( 'manage_product_cat_custom_column', 'wh_customFieldsListDisplay' , 10, 3); //Populating the Columns
/**
* Meta Title and Description column added to category admin screen.
*
* @param mixed $columns
SELECT p.`ID`,
p.`post_title` AS coupon_code,
p.`post_excerpt` AS coupon_description,
Max(CASE WHEN pm.meta_key = 'discount_type' AND p.`ID` = pm.`post_id` THEN pm.`meta_value` END) AS discount_type, -- Discount type
Max(CASE WHEN pm.meta_key = 'coupon_amount' AND p.`ID` = pm.`post_id` THEN pm.`meta_value` END) AS coupon_amount, -- Coupon amount
Max(CASE WHEN pm.meta_key = 'free_shipping' AND p.`ID` = pm.`post_id` THEN pm.`meta_value` END) AS free_shipping, -- Allow free shipping
Max(CASE WHEN pm.meta_key = 'expiry_date' AND p.`ID` = pm.`post_id` THEN pm.`meta_value` END) AS expiry_date, -- Coupon expiry date
Max(CASE WHEN pm.meta_key = 'minimum_amount' AND p.`ID` = pm.`post_id` THEN pm.`meta_value` END) AS minimum_amount, -- Minimum spend
Max(CASE WHEN pm.meta_key = 'maximum_amount' AND p.`ID` = pm.`post_id` THEN pm.`meta_value` END) AS maximum_amount, -- Maximum spend
Max(CASE WHEN pm.m
[
{
"keys": ["ctrl+alt+c"],
"command": "copy_path"
},
{
"keys": ["shift+command+m"],
"command": "goto_definition"
},
{
@web-hat
web-hat / old-shipment-tracking.php
Last active September 20, 2017 18:54
For Shipment Tracking version 1.3.6 or below
<?php
$order_id = method_exists($order, 'get_id') ? $order->get_id() : $order->id;
//getting shipping details
$tracking_number = get_post_meta($order_id, '_tracking_number', TRUE);
if (isset($tracking_number) && !empty($tracking_number)) {
$order_data['shipping_details'] = array(
'tracking_provider' => get_post_meta($order_id, '_tracking_provider', TRUE),
'tracking_number' => $tracking_number,
@web-hat
web-hat / shipment-tracking.php
Last active November 19, 2017 14:35
For Shipment Tracking version 1.4.0 or above
<?php
$order_id = method_exists($order, 'get_id') ? $order->get_id() : $order->id;
//getting shipping details
$objWC_Shipment = WC_Shipment_Tracking_Actions::get_instance();
$shipping_details = $objWC_Shipment->get_tracking_items($order_id);
if (!empty($shipping_details)) {
foreach ($shipping_details as $shipping_detail) {
$order_data['shipping_details'][] = array(
@web-hat
web-hat / usage-getOrderDetailById.php
Last active September 20, 2017 05:11
Usage of getOrderDetailById()
<?php
$order_detail = getOrderDetailById(101); //to get the detail of order ID #101
print_r($order_detail);
@web-hat
web-hat / get-order-detail-by-order-id-2_6.php
Last active September 8, 2018 17:24
Works with WooCommerce 2.6.x or below
<?php
if (!function_exists('getOrderDetailById')) {
function getOrderDetailById($id, $fields = null, $filter = array()) {
if (is_wp_error($id))
return $id;
// Get the decimal precession
@web-hat
web-hat / get-order-detail-by-order-id.php
Last active September 11, 2022 17:11
Works with WooCommerce 3.x or above
<?php
if (!function_exists('getOrderDetailById')) {
//to get full order details
function getOrderDetailById($id, $fields = null, $filter = array()) {
if (is_wp_error($id))
return false;
@web-hat
web-hat / eloquent-query.php
Created April 5, 2017 03:20
Multiple DB Connections in Laravel 5
<?php
//create an instance of your model
$objMyModel = new MyModel();
//query for fetching data
$data = $objMyModel->setConnection('mysql_second')
->select('col_1')
->get();