Skip to content

Instantly share code, notes, and snippets.

View gonzalesc's full-sized avatar

Alexander gonzalesc

View GitHub Profile
@gonzalesc
gonzalesc / wc_multiple_products_to_cart.php
Created March 25, 2025 06:25
Add multiple products to cart in the URL in WooCommerce
<?php
add_action( 'wp_loaded', 'maybeAddMultipleProductToCart', 25 );
/**
* Add Multiple products by URL
* @example
* simple: http://wpplugins.local/cart/?add-to-cart=27,28
* variation : http://wpplugins.local/cart/?add-to-cart=208,32
* @return void
* @throws Exception
@gonzalesc
gonzalesc / create_custom_endpoint_to_wp.php
Created February 28, 2025 07:32
Create custom endpoint to WordPress
<?php
/**
* Create custom RestAPI
* @link http://wpplugins.local/wp-json/letsgo/v1/activatePlugin
* @return void
*/
add_action( 'rest_api_init', function (): void {
register_rest_route(
'letsgo/v1', '/activatePlugin', [
@gonzalesc
gonzalesc / wc-create-user-moodle.php
Created January 28, 2025 04:35
Create an user Moodle when the payment is completed in WooComerce
<?php
/**
* Payment Complete in WC
*/
add_action( 'woocommerce_payment_complete', 'createMoodleUser' );
/**
* Create Moodle User
* @param int $orderID
@gonzalesc
gonzalesc / addProductCustomFileds.php
Created January 23, 2025 18:32
How to add product custom fields in WooCommerce
<?php
/******************
* Product Hooks
******************/
// Print a product custom field
add_action( 'woocommerce_before_add_to_cart_button', 'printProductCustomFields' );
/***************
* Cart Hooks
***************/
@gonzalesc
gonzalesc / convert_wc_in_catalog_mode.php
Created January 19, 2025 08:13
Convert your WooCommerce in catalog mode
<?php
/**
* Convert your Ecommerce in catalog mode
* @package LetsGodev\MuPlugins
* @since 1.0
*/
// Hide the cart page & checkout page
add_action( 'template_redirect', 'hideCartCheckoutPage' );
@gonzalesc
gonzalesc / free_shipping_by_subtotal.php
Created January 5, 2025 10:18
Free Shipping method by Subtotal in WooCommerce
<?php
/*********
* Hooks
* Remember to remove shipping-transient-version transient
********/
// Snippet 1 : Hide other shipping methods
add_filter( 'woocommerce_package_rates', 'maybeFreeShipping' );
// Snippet 2 : Notify that the customer can access free shipping.
@gonzalesc
gonzalesc / set_minimum_order_example_plugin.php
Created December 22, 2024 19:57
Example plugin - Set mininum order in WooCommerce
<?php
/**
* @link https://www.letsgodev.com/
* @since 1.0.0
* @package Plugins/LetsGoDev/PluginExample
*
* Plugin Name: Set minimum order
* Plugin URI: https://www.letsgodev.com/
* Description: This plugin is an example
* Version: 1.0.0
@gonzalesc
gonzalesc / new_basic_custom_plugin.php
Created December 22, 2024 19:53
New Custom Plugin - Example plugin
<?php
/**
* @link https://www.letsgodev.com/
* @since 1.0.0
* @package Plugins/LetsGoDev/PluginExample
*
* Plugin Name: Plugin Example
* Plugin URI: https://www.letsgodev.com/
* Description: This plugin is an example
* Version: 1.0.0
@gonzalesc
gonzalesc / tie_down_authors.php
Created December 20, 2024 18:38
Tie down authors to see only their own posts on WordPress
<?php
/**
* Tie down authors to see only their own posts
* @package LetsGodev\MuPlugins
* @since 1.0.0
*/
add_filter( 'pre_get_posts', 'tieDownAuthors' );
/**
* Tie down authors to see only their own posts
@gonzalesc
gonzalesc / send_php_to_js.php
Created December 17, 2024 16:58
Send PHP variables to script JS
<?php
/**
* Send php variables to js
* @package LetsGodev\MuPlugins
* @since 1.0
* @description : use letsgo_vars.ajax_url in script js
*/
add_action( 'wp_enqueue_scripts', 'sendVarsToScripts' );