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 / add-multiple-products-cart-url.php
Created May 15, 2023 17:41
Add multiple products to cart via URL WooCommerce
<?php //remover esta línea
function dcms_add_multiple_products_to_cart( $url = false ) {
if ( ! class_exists( 'WC_Form_Handler' ) || empty( $_REQUEST['add-to-cart'] ) || false === strpos( $_REQUEST['add-to-cart'], ',' ) ) {
return;
}
remove_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ), 20 );
$product_ids = explode( ',', $_REQUEST['add-to-cart'] );
@jmarreros
jmarreros / relations_cpt.php
Created March 8, 2023 14:09
Class for saving bidirectional relations between CPTs WordPress and ACF
<?php
/**
** Class for saving relations between CPT in ACF
**/
class RelationsCPT {
public function __construct() {
add_filter( 'acf/update_value/name=jugadores', [ $this, 'update_players_team' ], 10, 2 );
add_filter( 'acf/update_value/name=equipos', [ $this, 'update_teams_player' ], 10, 2 );
@jmarreros
jmarreros / request-quote-woocommerce.php
Created November 1, 2022 17:02
Request a quote functionality in WooCommerce
<?php // No copiar este línea
add_action('woocommerce_share', 'dcms_show_request_quote_form');
function dcms_show_request_quote_form(){
global $product;
if ( isset($_GET['sent']) ){
$message = $_GET['sent'] ? 'Solicitud enviada' : 'Hubo un error';
echo "<p class='msg-request-quote'>$message</p>";
return;
@jmarreros
jmarreros / copy-clipboard.js
Last active August 1, 2022 13:08
Copy text to clipboard using jquery
/*
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 July 5, 2022 15:50
Change Add to Cart Quantity into a Select Drop-down, overrides template: woocommerce/global/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 18:46
Filtros personalizados de marca y stock
<?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 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;