Skip to content

Instantly share code, notes, and snippets.

View web-hat's full-sized avatar

WebHat web-hat

View GitHub Profile
<?php
//Defining a connection in Query Builder
$data = DB::connection('mysql_second')
->table('table_name')
->select('col_1')
->get();
//Defining a connection within the Schema Builder.
Schema::connection('mysql_second')->create('table_name', function($table) {
<?php
class MyModel extends Eloquent {
//...
protected $connection = 'mysql_second';
//...
//...
}
@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();
@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 / 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 / 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 / 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 / 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,
[
{
"keys": ["ctrl+alt+c"],
"command": "copy_path"
},
{
"keys": ["shift+command+m"],
"command": "goto_definition"
},
{
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