Skip to content

Instantly share code, notes, and snippets.

View rayflores's full-sized avatar

Ray Flores rayflores

View GitHub Profile
@8ctopotamus
8ctopotamus / count-repeater-fields-in-acf-flexible-content-example.php
Last active February 23, 2024 20:58
Count number of repeater fields in ACF flexible content.
// Source: https://katienelson.co.uk/developer-acf-counting-repeater-rows-inside-flexible-content/
// The following code doesn’t work with a repeater field if it is part of a flexible content block.
<?php
if(have_rows('card')):
$cards = get_sub_field('card');
$number_of_cards = count($cards);
endif;
?>
@abegit
abegit / wc_order_status_changes.php
Created February 2, 2016 20:11
WooCommerce Hooks for Order Status Changes
function mysite_pending($order_id) {
error_log("$order_id set to PENDING", 0);
}
function mysite_failed($order_id) {
error_log("$order_id set to FAILED", 0);
}
function mysite_hold($order_id) {
error_log("$order_id set to ON HOLD", 0);
}
function mysite_processing($order_id) {
@claudiosanches
claudiosanches / functions.php
Last active June 4, 2022 07:52
WooCommerce - Add Order Again button to My Orders actions
<?php
/**
* Add order again button in my orders actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
@bekarice
bekarice / wc-memberships-renew-with-purchase.php
Last active March 11, 2022 01:36
WooCommerce Memberships: Change a Renewal Link to Purchase a Different Membership
<?php
// Changes the renewal link for a particular membership to purchase a new one
// Old membership will be deleted upon purchase if expired
/**
* Changes the renewal URL for the trial membership
*
* @param string $url the renewal URL
* @param \WC_Memberships_User_Membership $membership the user membership
* @return string $url the updated renewal URL
@lucasstark
lucasstark / Exclude Products from Dynamic Pricing Global Discounts
Created July 8, 2015 10:02
Exclude Products from Dynamic Pricing Global Discounts
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'wcdp_exclude_specific_products', 10, 2 );
function wcdp_exclude_specific_products( $include, $product ) {
//Adjust this array accordingly. Alternatively use a product category.
$products_to_exclude = array(
1,
101,
717
);
@claudiosanches
claudiosanches / plugin.php
Created May 28, 2015 17:49
WooCommerce - Custom templates in plugin
function cs_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) {
$template_path = $woocommerce->template_url;
}
$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/';
// Look within passed path within the theme - this is priority
@claudiosanches
claudiosanches / credit-card.md
Created April 29, 2015 15:59
Credit Card - Snippets

Credit Card

Credit Card numbers for test

Credit card type EBANX payment type code Credit card numbers
American Express amex 378282246310005 or 371449635398431
Aura aura 5078601870000127985 or 5078601800003247449
Diners Club diners 30569309025904 or 38520000023237
Discover discover 6011111111111117
@thenbrent
thenbrent / no-renewal-emails-for-zero-reneawl.php
Last active August 26, 2023 07:35
Do not send renewal order emails when the email relates to a $0 renewal.
<?php
/*
Plugin Name: WooCommerce Subscriptions No $0 Emails
Plugin URI:
Description: Do not send processing or completed renewal order emails to customers when the order or renewal is for $0.00.
Author:
Author URI:
Version: 0.1
*/