Skip to content

Instantly share code, notes, and snippets.

View corsonr's full-sized avatar

Remi Corson corsonr

View GitHub Profile
@corsonr
corsonr / gist:1992502d052898cd386a
Created June 16, 2014 14:24
WooCommerce re-include order notes in comments list
<?php
// Brings WooCommerce order notes back in the comments list
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) );
@corsonr
corsonr / gist:e5e5c5fc944c278049de
Created June 17, 2014 13:11
WooCommerce Subscriptions: edit sign-up button text
<?php
function woocommerce_custom_subscription_product_single_add_to_cart_text( $text = '' , $post = '' ) {
global $product;
if ( $product->is_type( 'subscription' ) ) {
$text = get_option( WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text', __( 'Sign Up Now', 'woocommerce-subscriptions' ) );
} else {
$text = $product->add_to_cart_text(); // translated "Read More"
}
@corsonr
corsonr / gist:f8c8b49c1b030d5b2e40
Created July 10, 2014 09:00
WPdonations: add new custom fields to the administration
// Add your own function to add the fields
add_filter( 'wpdonations_donation_data_fields', 'admin_add_fields' );
// Add new fields to the edit donation screen in the administration
function admin_add_fields( $fields ) {
$fields['_donor_phone'] = array(
'label' => __( 'Phone', 'wpdonations' ),
'type' => 'text',
'placeholder' => '',
'description' => ''
@corsonr
corsonr / gist:4d644c91267953c41fe7
Created August 26, 2014 12:01
WPdonations: one form per campaign
<?php
add_filter( 'wp_footer' , 'add_wpdonations_scripts' );
/**
* add_wpdonations_scripts
*
* @access public
* @since 1.0
* @return void
@corsonr
corsonr / gist:4a1f65b9fff95bd5d03c
Created December 29, 2014 09:17
Allow WooCommerce customers to read private posts
<?php
// In functions.php
$customer_role = get_role( 'customer' );
$customer_role->add_cap( 'read_private_posts' );
$customer_role->add_cap( 'read_private_pages' );
@corsonr
corsonr / gist:93ace14a42e732806b2a
Created February 6, 2015 09:07
WPdonations: make a field required
// Add your own function to filter the fields
add_filter( 'submit_donation_form_fields', 'custom_submit_donation_form_fields' );
// This is your function which takes the fields, modifies them, and returns them
// You can see the fields which can be changed in: includes/forms/class-wpdonations-form-submit-donation.php
function custom_submit_donation_form_fields( $fields ) {
// Here we target one of the donation fields (donation_message) and change it's "required" value to true
$fields['donation']['donation_message']['required'] = true;
@corsonr
corsonr / gist:d77044e88c4f373a1f98
Last active August 29, 2015 14:15
Fix Shipment Tracking / Subscriptions issue
/**
* Don't transfer Shipment Tracking meta when creating a renewal order.
*
* @access public
* @param array $order_meta_query MySQL query for pulling the metadata
* @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed
* @param int $renewal_order_id Post ID of the order created for renewing the subscription
* @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child'
* @return void
*/
@corsonr
corsonr / gist:a4f554950a662fe7f7c0
Created May 6, 2015 13:10
WooCommerce: create a custom button in Tools
<?php
/*
Plugin Name: WC Tools - Custom Button
Plugin URI: http://remicorson.com
Description: A simple plugin to add a custom button to WooCommerce tools
Author: Remi Corson
Contributors: corsonr
Author URI: http://remicorson.com
Version: 1.0
/*
@corsonr
corsonr / gist:894a4c520e774ab2c505
Created June 22, 2015 10:26
WooCommerce: create a custom section in system status
<?php
add_action( 'woocommerce_system_status_report', 'render_debug_section' );
/**
* Renders the debug section
*/
function render_debug_section() {
?>
<table class="wc_status_table widefat" cellspacing="0" id="status">
@corsonr
corsonr / wc_api_v1_to_xml.php
Created August 17, 2015 10:06
WooCommerce: retrieve API V1 response in XML
<?php
add_filter( 'woocommerce_api_default_response_handler' , 'set_woocommerce_api_default_response_handler_to_xml' );
/**
* set_woocommerce_api_default_response_handler_to_xml
*
* @access public
* @since 1.0
* @return void