Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Trang Sĩ Hưng trangsihung

🏠
Working from home
View GitHub Profile
@trangsihung
trangsihung / _blank.js
Created Mar 2, 2020 — forked from CrocoDillon/_blank.js
Automatically open external links in new tab or window.
View _blank.js
// vanilla JavaScript
var links = document.links;
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname) {
links[i].target = '_blank';
}
}
// or in jQuery
View gist:bb5b420400eefdc16fb8517630ad602e
<?php
function wpmlsupp_1706_reset_wpml_capabilities() {
if ( function_exists( 'icl_enable_capabilities' ) ) {
icl_enable_capabilities();
}
}
add_action( 'shutdown', 'wpmlsupp_1706_reset_wpml_capabilities' );
@trangsihung
trangsihung / woo_min_max_price.php
Created Sep 4, 2018
Get filtered min price for products
View woo_min_max_price.php
<?php
/* Source: woocommerce\includes\widgets\class-wc-widget-price-filter.php:119 */
function woo_get_filtered_price() {
global $wpdb;
$args = wc()->query->get_main_query()->query_vars;
$tax_query = isset( $args['tax_query'] ) ? $args['tax_query'] : array();
$meta_query = isset( $args['meta_query'] ) ? $args['meta_query'] : array();
if ( ! is_post_type_archive( 'product' ) && ! empty( $args['taxonomy'] ) && ! empty( $args['term'] ) ) {
View autocomplete_taxonomies.php
<?php
add_filter( 'vc_autocomplete_[shortcode_base]_[param_name]_callback', 'vc_autocomplete_taxonomies_field_search', 10, 1 );
add_filter( 'vc_autocomplete_[shortcode_base]_[param_name]_render', 'vc_autocomplete_taxonomies_field_render', 10, 1 );
$args = array(
'name' => 'Shortcode Name',
'base' => 'shortcode_base',
'category' => __( 'Themes Elements', 'vtm' ),
'params' => array(
array(
View wp_upload_from_url.php
<?php
// Upload image from url
// Returns an array (attachment_id, url), or false
function media_import_from_url( $url ) {
$filename = basename($url);
global $wpdb;
$query = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value LIKE '%/$filename'";
$count = intval($wpdb->get_var($query));
View gist:fa23188ab77a724289fcbef1df4723de
<?php
// visual composer is enabled for a post/page
$vc_enabled = get_post_meta($post_id, '_wpb_vc_js_status', true);
View checkbox.css
.checkbox {
input[type="checkbox"], input[type="radio"] { display: none; }
label {
position: relative;
padding-left: 20px;
&:before {
content: '';
width: 15px; height: 15px;
border: 1px solid #fff;
@trangsihung
trangsihung / disable_right_click.js
Last active Mar 8, 2019
reset masonry after ajax called
View disable_right_click.js
document.addEventListener('contextmenu', event => event.preventDefault());
View add_customer_detail_on_email_woo.php
// class-wc-emails.php:443
public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
// if ( ! is_a( $order, 'WC_Order' ) ) {
// return;
// }
$fields = array();
if ( $order->customer_note ) {
View script.js
$('.mobile-toggle a').on('click', function(e) {
e.preventDefault();
$('.mobile-nav-overlay').fadeIn(400, function() {
$('.mobile-nav-outer').addClass('opened');
});
});
$('.mobile-nav-overlay .close-button').on('click', function(e) {
e.preventDefault();
$('.mobile-nav-outer').removeClass('opened');