Skip to content

Instantly share code, notes, and snippets.

View paulotruta's full-sized avatar
:shipit:
Focusing

Paulo Truta paulotruta

:shipit:
Focusing
View GitHub Profile
@paulotruta
paulotruta / call_api.php
Last active March 20, 2018 13:47
A simple method that uses CURL to send a request to an API and receive its response
// Method: POST, PUT, GET etc
// Data: array("param" => "value") ==> index.php?param=value
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
@paulotruta
paulotruta / php-block.js
Created July 30, 2018 08:32 — forked from pento/php-block.js
Converting a shortcode to a block
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@paulotruta
paulotruta / functions.php
Created September 23, 2018 18:52 — forked from filipecsweb/functions.php
Stop sending "processing order" e-mail when WooCommerce order status changes from pending to on-hold
<?php
/**
* Disable action that sends e-mail to customer, warning that his/her order is processing,
* as this is not true, because when the status changes from pending to on-hold,
* the order is not processing yet.
*
* @return void
*/
function manipulate_woocommerce_email_sending($email_class){
remove_action('woocommerce_order_status_pending_to_on-hold_notification', array($email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger'));
@paulotruta
paulotruta / flywheel-local-xdebug-vscode.md
Created October 15, 2018 11:11 — forked from ahmadawais/flywheel-local-xdebug-vscode.md
Debug WordPress with Visual Studio Code | VSCode WordPress Debug Setup | WordPress xDebug Setup for Local by FlyWheel with VSCode | Part of the VSCode Learning Course → https://VSCode.pro

VSCode WordPress Debugging Setup: WordPress Xdebug Setup for Local by FlyWheel with VSCode


🚅 TL;DR

  • Make sure your Local by FlyWheel WordPress install is a custom install
  • Configure xdebug.remote_autostart = 1
@paulotruta
paulotruta / Random-string
Created January 22, 2019 18:01 — forked from 6174/Random-string
Generate a random string in JavaScript In a short and fast way!
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@paulotruta
paulotruta / gist:b69d2557a8d5cf34d0d2f6a51601984e
Created January 25, 2019 10:33 — forked from mikejolley/gist:1926284
WooCommerce - Change WooCommerce email subject lines
/*
* goes in theme functions.php or a custom plugin
*
* Subject filters:
* woocommerce_email_subject_new_order
* woocommerce_email_subject_customer_processing_order
* woocommerce_email_subject_customer_completed_order
* woocommerce_email_subject_customer_invoice
* woocommerce_email_subject_customer_note
* woocommerce_email_subject_low_stock
@paulotruta
paulotruta / filter-wc-orders-by-gateway.php
Created March 14, 2019 14:38 — forked from bekarice/filter-wc-orders-by-gateway.php
Filters WooCommerce Orders by Payment Gateway Used
<?php
/**
* Plugin Name: Filter WooCommerce Orders by Payment Method
* Plugin URI: http://skyverge.com/
* Description: Filters WooCommerce orders by the payment method used :)
* Author: SkyVerge
* Author URI: http://www.skyverge.com/
* Version: 1.0.0
* Text Domain: wc-filter-orders-by-payment
*
@paulotruta
paulotruta / woocommerce-products.sql
Created June 13, 2019 10:20 — forked from mglaman/woocommerce-products.sql
MySQL query for wooCommerce to export products.
SELECT product.ID as product_id, product.post_title as product_name, replace(product.post_content, '"', "'") as product_content, product_sku.meta_value as product_sku, product_price.meta_value as product_price, product_weight.meta_value as product_weight
FROM wp_posts as product
LEFT JOIN wp_postmeta as product_sku ON product.ID = product_sku.post_ID
LEFT JOIN wp_postmeta as product_price ON product.ID = product_price.post_ID
LEFT JOIN wp_postmeta as product_weight ON product.ID = product_weight.post_ID
WHERE (product.post_type = 'product' OR product.post_type = 'product_variation') AND product_sku.meta_key = '_sku' AND product_price.meta_key = '_price' AND product_weight.meta_key = '_weight'
ORDER BY product_id ASC
@paulotruta
paulotruta / wpmltranslatedposts.php
Created February 7, 2019 17:20
Get WPML translated post ids from original post ID
<?php
function get_translated_post_ids($post_id) {
global $sitepress;
$translated_ids = Array();
if(!isset($sitepress)) return;
$trid = $sitepress->get_element_trid($post_id, 'post_product');
$translations = $sitepress->get_element_translations($trid, 'product');
foreach( $translations as $lang=>$translation){