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('wp_footer', 'test_func'); | |
function test_func() { | |
error_log("WORDPRESS OUTPUT_______"); | |
error_log( "get_option('gmt_offset') returns: " . get_option('gmt_offset') ); | |
error_log( "get_option('timezone_string') returns: " . get_option('timezone_string') ); | |
$blogtime = current_time( 'mysql' ); | |
list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $blogtime ); | |
error_log( "current_time( 'mysql' ) returns local site time: " . current_time( 'mysql' ) ); | |
error_log( "current_time( 'mysql', 1 ) returns GMT: " . current_time( 'mysql', 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 | |
/** | |
* Automatically add product to cart on visit | |
*/ | |
add_action( 'template_redirect', 'add_product_to_cart' ); | |
function add_product_to_cart() { | |
$product_ids = array( 128,132,140 ); //replace with your own product ids separated by commas | |
foreach( $product_ids as $product_id) { | |
if ( is_product($product_id) ) { | |
$found = false; |
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 | |
// note: this would require the store settings to be set to "capture" to begin with | |
function wc_authorize_net_cim_credit_card_change_transaction_type_no_subs( $settings ) { | |
if ( method_exists( 'WC_Subscriptions_Cart' , 'cart_contains_subscription' ) ) { | |
if ( ! WC_Subscriptions_Cart::cart_contains_subscription() ) { | |
$settings['transaction_type'] = 'authorization'; | |
} | |
} |
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 remove_dashboard_widgets() { | |
// remove WooCommerce Dashboard Status | |
remove_meta_box( 'woocommerce_dashboard_status', 'dashboard', 'normal'); | |
} | |
add_action('wp_user_dashboard_setup', 'remove_dashboard_widgets', 20); | |
add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 20); |
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 | |
if (is_account_page()) { | |
$user = wp_get_current_user(); | |
if ( in_array( 'EXAMPLE_ROLE', (array) $user->roles ) ) { | |
add_filter( 'woocommerce_subscriptions_can_item_be_switched', '__return_false', 100 ); | |
} | |
} |
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 auto_remove_coupon_sub( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) | |
return; | |
if ( method_exists( 'WC_Subscriptions_Cart' , 'cart_contains_subscription' ) ) { |
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 ) ); | |
} |
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 | |
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 | |
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(); |