Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Jhon Marreros Guzman jmarreros

🏠
Working from home
View GitHub Profile
@jmarreros
jmarreros / copy-clipboard.js
Last active Aug 1, 2022
Copy text to clipboard using jquery
View copy-clipboard.js
/*
Container with class: "copy"
copy the text after the ":" character
var copyImg has the img path
*/
(function( $ ) {
'use strict';
// Append copy image to text
@jmarreros
jmarreros / quantity-input.php
Created Jul 5, 2022
Change Add to Cart Quantity into a Select Drop-down, overrides template: woocommerce/global/quantity-input.php
View quantity-input.php
<?php
/**
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 4.0.0
*/
defined( 'ABSPATH' ) || exit;
if ( $max_value && $min_value === $max_value ) {
@jmarreros
jmarreros / custom-filters-woocommerce.php
Last active May 7, 2022
Filtros personalizados de marca y stock
View custom-filters-woocommerce.php
<?php
// Set query vars
add_filter('query_vars', 'dcms_add_query_vars');
function dcms_add_query_vars($query_vars) {
$query_vars[] = "dcms-stock";
$query_vars[] = "dcms-brand";
return $query_vars;
}
@jmarreros
jmarreros / sessions_wordpress.php
Created Mar 29, 2022
Guarda el nombre del usuario enviado desde un formulario CF7 y lo imprime en una página
View sessions_wordpress.php
<?php // No copiar esta línea
add_action( 'init', 'dcms_session_start' );
function dcms_session_start() {
if ( ! session_id() ) {
session_start(); // Iniciamos la sesion
}
}
add_action( 'wpcf7_submit', 'dcms_action_wpcf7_submit', 10, 2 );
@jmarreros
jmarreros / move-variation-price.php
Created Mar 22, 2022
Move product price variation to top WooCommerce
View move-variation-price.php
<?php // No copiar este línea
add_action( 'wp_footer', 'dcms_add_script_footer' );
function dcms_add_script_footer() {
if ( ! is_product() ) return;
?>
<script>
jQuery(function ($) {
$('.variations_form').on('woocommerce_variation_has_changed', function () {
@jmarreros
jmarreros / add-blog-slug-posts-wordpress.php
Created Feb 16, 2022
Agregar slug "blog" en articulos WordPress
View add-blog-slug-posts-wordpress.php
<?php // No copiar esta línea
add_action('generate_rewrite_rules', 'dcms_posts_add_rewrite_rules');
function dcms_posts_add_rewrite_rules( $wp_rewrite ){
$slug = "blog";
$new_rules = [
$slug.'/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged='. $wp_rewrite->preg_index(1),
$slug.'/(.+?)/?$' => 'index.php?post_type=post&name='. $wp_rewrite->preg_index(1),
];
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
@jmarreros
jmarreros / search-custom-table-with-shortcode.php
Last active Feb 1, 2022
Búsqueda en una tabla personalizada de WordPress usando un Shortcode
View search-custom-table-with-shortcode.php
<?php // No copiar esta línea
// ShortCode
add_action( 'init', 'dcms_frm_shortcode' );
function dcms_frm_shortcode(){
add_shortcode('search-form', 'dcms_search_form');
}
function dcms_search_form( $atts , $content ){
global $wpdb;
View save_search_wordpress.php
<?php
function dcms_count_text_search( $query_object ) {
if( $query_object->is_search() ) {
global $wpdb;
$table = $wpdb->prefix . 'text_search'; //Nombre de la tabla
$col_search = 'search'; //unique
$col_count = 'count';
@jmarreros
jmarreros / custom-table-search-pagination.php
Last active Nov 16, 2021
Muestra los datos de una tabla personalizada en una página de WordPress incluye paginación y búsqueda
View custom-table-search-pagination.php
<?php //don't copy this line
// Show custom table data in a WordPress specific page
// includes pagination and search
add_filter( 'the_content', 'dcms_list_data' );
function dcms_list_data( $content ) {
$slug_page = 'empleados'; //slug page where show data
$table_name = 'employee'; // custom table name
@jmarreros
jmarreros / custom-text-field-produt-woocommerce.php
Last active Nov 3, 2021
Add custom text field attribute WooCommerce
View custom-text-field-produt-woocommerce.php
<?php
// show custom field in product page
function dcms_display_field() {
// Optional validation for specif category
// global $product;
// $categories = $product->get_category_ids();
// if ( ! in_array(34, $categories )) return;