Skip to content

Instantly share code, notes, and snippets.

View seb86's full-sized avatar
🚀

Sébastien Dumont seb86

🚀
View GitHub Profile
@seb86
seb86 / wc-rest-api-products-images.php
Created March 27, 2023 20:13
WooCommerce REST API (Products) - Get the images for a product or product variation and returns all image sizes.
<?php
if ( ! function_exists( 'wc_rest_get_product_images' ) ) {
add_filter( 'woocommerce_rest_prepare_product_object', 'wc_rest_get_product_images', 10, 2 );
/**
* Get the images for a product or product variation
* and returns all image sizes.
*
* @param WP_REST_Request $request Request object.
* @param WC_Product|WC_Product_Variation $product Product instance.
@seb86
seb86 / woocommerce-admin-hooked.php
Created February 9, 2023 23:55
Initializes WooCommerce Admin only in the backend.
<?php
/**
* Plugin Name: WooCommerce Admin
* Description: Initializes WooCommerce Admin only in the backend.
* Version: 0.0.1
*/
add_action( 'plugins_loaded', function() {
if ( is_admin() ) {
\Automattic\WooCommerce\Admin\Composer\Package::init();
@seb86
seb86 / woocommerce-lite.php
Created February 9, 2023 23:26
A must-use plugin that removes the need to run the packages within WooCommerce making it run better for performance.
<?php
/**
* Plugin Name: WooCommerce Lite
* Description: Removes the need to run the packages within WooCommerce making it run better for performance.
* Version: 0.0.1
*/
add_action( 'upgrader_process_complete', 'depackage_woocommerce_after_update', 10, 2 );
function depackage_woocommerce_after_update( $upgrader_object, $options ) {
@seb86
seb86 / cocart-totals-html.php
Last active July 15, 2021 05:15
Return totals in cart response formatted.
<?php
add_filter( 'cocart_cart', 'cocart_totals_html' );
function cocart_totals_html( $cart ) {
$decimals = wc_get_price_decimals();
foreach( $cart['totals'] as $total => $value ) {
$value = substr_replace( $value, '', intval( '-' . $decimals ) );
$cart['totals'][$total] = html_entity_decode( strip_tags( wc_price( $value ) ) );
}
@seb86
seb86 / adding_new_webhook_topics.php
Created January 27, 2021 12:43 — forked from jessepearson/adding_new_webhook_topics.php
How to add a new custom Webhook topic in WooCommerce, with example of order filtering.
<?php // do not copy this line
/**
* add_new_topic_hooks will add a new webhook topic hook.
* @param array $topic_hooks Esxisting topic hooks.
*/
function add_new_topic_hooks( $topic_hooks ) {
// Array that has the topic as resource.event with arrays of actions that call that topic.
@seb86
seb86 / create-custom-subscription-webhooks.php
Created January 27, 2021 12:42 — forked from dhirenpatel22/create-custom-subscription-webhooks.php
Create custom hooks for WooCommerce Subscription status change to cancelled and subscription status change to active
<?php
function add_custom_filters_and_actions() {
add_filter( 'woocommerce_webhook_topic_hooks', 'add_custom_wcs_topics', 30, 2 );
add_filter( 'woocommerce_valid_webhook_events', 'add_custom_wcs_events', 20, 1 );
add_filter( 'woocommerce_webhook_topics' , 'add_custom_wcs_topics_admin_menu', 20, 1 );
@seb86
seb86 / functions.php
Created January 27, 2021 12:26 — forked from jessepearson/functions.php
Will clear out all the specified completed scheduled actions, 5000 at a time.
<?php // do not copy this line
/**
* Will clear out all the specified completed scheduled actions, 5000 at a time.
*/
function clear_woocommerce_scheduled_actions_20200609() {
global $wpdb;
$limit = 5000;
$actions_table = $wpdb->prefix . 'actionscheduler_actions';
$logs_table = $wpdb->prefix . 'actionscheduler_logs';
@seb86
seb86 / functions.php
Created January 27, 2021 12:25 — forked from jessepearson/functions.php
Dequeue the JavaScript files from WooCommerce Square on all pages except the checkout page.
<?php // do not copy this line
/**
* Note: This has not been tested on a live site and is to be used at your own risk.
*
* This will dequeue the JavaScript files from WooCommerce Square on all pages except the checkout page.
*/
add_action( 'wp_enqueue_scripts', 'dequeue_wc_square_js_scripts_20200713', 999 );
function dequeue_wc_square_js_scripts_20200713() {
// Not needed in admin, and we want to keep in checkout
@seb86
seb86 / increase-variation-threshold.php
Created January 27, 2021 12:23 — forked from jessepearson/increase-variation-threshold.php
Increase the number of variations loaded in the WooCommerce front end for dynamic filtering of available variations in the drop down lists.
<?php //only copy this line if needed
/**
* Function filters the threshold for the amount of variables to load in the front end.
*
* @see https://woocommerce.wordpress.com/2015/07/13/improving-the-variations-interface-in-2-4/
* @param int $threshold Default of 30
* @return int 100 The new threshold.
*/
function lets_increase_the_variation_threshold( $threshold ) {
<?
# MIT license, do whatever you want with it
#
# This is my invoice.php page which I use to make invoices that customers want,
# with their address on it and which are easily printable. I love Stripe but
# their invoices and receipts were too wild for my customers on Remote OK
#
require_once(__DIR__.'/../vendor/autoload.php');