Skip to content

Instantly share code, notes, and snippets.

View jmarreros's full-sized avatar
🏠
Working from home

Jhon Marreros Guzman jmarreros

🏠
Working from home
View GitHub Profile
@jmarreros
jmarreros / sessions_wordpress.php
Created March 29, 2022 15:53
Guarda el nombre del usuario enviado desde un formulario CF7 y lo imprime en una página
<?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 March 22, 2022 16:48
Move product price variation to top WooCommerce
<?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 February 16, 2022 21:11
Agregar slug "blog" en articulos WordPress
<?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 February 1, 2022 15:47
Búsqueda en una tabla personalizada de WordPress usando un Shortcode
<?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;
<?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 November 16, 2021 21:48
Muestra los datos de una tabla personalizada en una página de WordPress incluye paginación y búsqueda
<?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 November 3, 2021 16:41
Add custom text field attribute WooCommerce
<?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;
@jmarreros
jmarreros / particles-js.php
Last active October 27, 2021 16:25
Integración de particles.js en WordPress con un shortcode
<?php
// The shortcode only works in WordPress front page
// Shortcode Creation
add_action( 'init', 'dcms_add_shortcode' );
function dcms_add_shortcode(){
add_shortcode('particles-background', 'dcms_particles_background');
}
@jmarreros
jmarreros / tabs.php
Created October 20, 2021 19:47
Cambia la estructura de tabs a acordeón
<?php
// Change template tabs.php estructure
// Copy this file to: /wp-content/TU_THEME/woocommerce/single-product/tabs/tabs.php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
@jmarreros
jmarreros / add-order-note-specific-product.php
Created September 19, 2021 22:56
Agrega una nota de usuario para un producto específico comparándolo con el SKU
<?php //No copiar esta línea
add_action( 'woocommerce_thankyou', 'we_note_order_product' );
function we_note_order_product( $order_id ) {
$order = wc_get_order( $order_id );
foreach ( $order->get_items() as $item ) {
$sku = $item->get_product()->get_sku();