Skip to content

Instantly share code, notes, and snippets.

@bernattorras
bernattorras / create_pending_orders_for_subscriptions.php
Created July 5, 2018 17:00
Function to create pending renewal orders for given subscriptions
<?php
/**
* Function to create pending renewal orders for given subscriptions
**/
add_action( 'init', 'create_pending_orders_for_subscriptions' );
function create_pending_orders_for_subscriptions(){
$subscriptions = array(76,72);
foreach($subscriptions as $subscription_id){
$subscription = wcs_get_subscription( $subscription_id );
@bernattorras
bernattorras / Register new Order status
Last active November 22, 2021 01:54
This snippet registers a new Order status.
<?php
/**
* Register new status
* Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/
**/
function register_holding_shipment_order_status() {
register_post_status( 'wc-holding-shipment', array(
'label' => 'Holding shipment',
'public' => true,
@bernattorras
bernattorras / disable_payment_gateways_on_trial_sub.php
Last active June 29, 2018 09:24
Disable payment gateways when the cart only contains subscriptions with free trial (allowing customers to purchase the subscription without adding any payment information)
<?php
// Disable Automatic Payments when the cart only contains subscriptions with free trial (allowing customers to purchase the subscription without adding any payment information)
add_filter('option_woocommerce_subscriptions_turn_off_automatic_payments','disable_payment_gateways_on_trial_sub', 1);
function disable_payment_gateways_on_trial_sub($automatic_payments_off){
if(!is_admin()){
$all_trial = WC_Subscriptions_Cart::all_cart_items_have_free_trial();
if($all_trial==1){
// All items in the cart contain a free trial
return 'yes'; // Turn off automatic payments (disabling payment gateways)
}