This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'wcs_disable_customer_order_email_if_sub', 10, 2 ); | |
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'wcs_disable_customer_order_email_if_sub', 10, 2 ); | |
// If order contains subscription we change the email recipient to "" | |
function wcs_disable_customer_order_email_if_sub( $recipient, $order ) { | |
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : ''; | |
if ( 'wc-settings' === $page ) { | |
return $recipient; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('woocommerce_cart_contents_weight', 'round_cart_contents_weight', 100, 1); | |
function round_cart_contents_weight($weight) { | |
return 100; | |
// return ceil($weight); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_payment_complete_order_status', 'my_function', 100, 3 ); | |
function my_function( $new_order_status, $order_id, $order = null ) { | |
if ( $new_order_status == 'completed' ) { | |
$new_order_status = 'processing'; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function change_text( $subscription_string, $subscription_details ) { | |
if ($subscription_string == '<span class="subscription-details">every 2 weeks</span>') { | |
$subscription_string = '<span class="subscription-details">Fortnightly</span>'; | |
} | |
if ($subscription_string == '<span class="subscription-details">every month</span>') { | |
$subscription_string = '<span class="subscription-details">Monthly</span>'; | |
} | |
return $subscription_string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Cancel all subscriptions. | |
* Description: Cancel all subscriptions. | |
* Version: 1.0 | |
*/ | |
// Prevent direct access to this file | |
if ( ! defined( 'ABSPATH' ) ) { | |
die( "You can't do anything by accessing this file directly." ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function aer_wc_subscription_updated( $subscription ) { | |
$logger = wc_get_logger(); | |
$logger->add( 'wcs-subscription-payment', "New payment for subscription #", $subscription->get_id() ); | |
} | |
add_action('woocommerce_subscription_payment_complete', 'aer_wc_subscription_updated', 10, 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function deactivate_paypal_unless_subscription( $available_gateways ) { | |
global $wp; | |
if ( class_exists( 'WC_Subscriptions_Cart' ) ) { | |
// version 1.5 and 2.0 compatibility | |
$cart_contains_renewal = function_exists( 'wcs_cart_contains_renewal' ) ? wcs_cart_contains_renewal() : WC_Subscriptions_Cart::cart_contains_subscription_renewal(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function preselect_option() { | |
// URL should be in the format https://xxxxxxx/?option=VALUE_OF_OPTION | |
$option = htmlspecialchars($_GET["option"]); | |
echo '<script>'; | |
echo 'function setSelectedIndex(s, valsearch) {'; | |
echo ' // Loop through all the items in drop down list'; | |
echo ' for (i = 0; i< s.options.length; i++) { '; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// apply free shipping coupon automatically when the cart total is >=$25 | |
add_action('woocommerce_before_cart_table', 'freeship_when_total_at_least_25'); | |
function freeship_when_total_at_least_25() { | |
global $woocommerce; | |
$cart_total = WC()->cart->get_cart_contents_total(); | |
if( $cart_total >= 25 ) { | |
$coupon_code = 'freeshipping'; // this requires the coupon of this name to already exist | |
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ))) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'subscriptions_activated_for_order', 'test_function' ); | |
function test_function( $order_id ) { | |
$subscription = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => array( 'any' ) )); | |
error_log( 'In ' . __FUNCTION__ . '(), $subscription = ' . var_export( $subscription, true ) ); | |
} |