Skip to content

Instantly share code, notes, and snippets.

@maxrice
maxrice / gist:6589105
Last active December 23, 2015 05:48
Add multiple elements to WooCommerce Customer/Order XML Export Suite
<?php
add_filter( 'wc_customer_order_xml_export_suite_order_export_order_list_format', function ( $order_format, $order ) {
$order_format['AddressCapabilities'] = array(
'AddressCapability' => array(
0 => array(
'@attributes' => array( 'AddressType' => 'MAIN' ),
),
1 => array(
@maxrice
maxrice / gist:6589202
Created September 17, 2013 02:00
Add custom line item meta to the WooCommerce Customer/Order XML Export Suite XML output
<?php
add_filter( 'wc_customer_order_xml_export_suite_order_export_line_item_format', function( $line_item_format, $order, $item ) {
// remove imploded meta
unset( $line_item_format['Meta'] );
// add custom meta
$line_item_format['YourFullName'] = woocommerce_get_order_item_meta( $item['id'], 'your_full_name', true );
return $line_item_format;
@maxrice
maxrice / gist:6772280
Created October 1, 2013 00:23
Automatically change the status for an order placed with a Check or BACS gateway
<?php
// Automatically update the order status to "completed" for cheque orders
function skyverge_auto_complete_on_hold_order( $order_id ) {
$order = new WC_Order( $order_id );
if ( 'on-hold' === $order->status )
$order->update_status( 'completed' );
}
@maxrice
maxrice / gist:7918315
Created December 11, 2013 20:55
Get SKU from products in an order
<?php
$order = new WC_Order( $order_id );
foreach ( $order->get_items() as $item_key => $item ) {
$product = $order->get_product_from_item( $item );
$sku = $product->get_sku();
@maxrice
maxrice / wc-hide-coupons.php
Last active January 4, 2016 01:49
WooCommerce - hide the coupon form everywhere, but leave coupons enabled for use with plugins like Smart Coupons and URL Coupons
<?php
// hide coupon form everywhere
function hide_coupon_field( $enabled ) {
if ( is_cart() || is_checkout() ) {
$enabled = false;
}
return $enabled;
@maxrice
maxrice / wc-hide-coupons-cart-checkout.php
Created January 21, 2014 23:43
WooCommerce - hide the coupon form on the cart or checkout page, but leave coupons enabled for use with plugins like Smart Coupons and URL Coupons
<?php
// hide coupon field on cart page
function hide_coupon_field_on_cart( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
@maxrice
maxrice / wc-rename-cart-coupon-field.php
Created January 21, 2014 23:53
WooCommerce - rename the "Apply Coupon" field on the cart page
<?php
// rename the coupon field on the cart page
function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
@maxrice
maxrice / wc-rename-checkout-coupon-field.php
Last active July 5, 2023 19:34
WooCommerce - rename the "Have a Coupon?" message and "Apply Coupon" field on the checkout
<?php
// rename the "Have a Coupon?" message on the checkout page
function woocommerce_rename_coupon_message_on_checkout() {
return 'Have a Promo Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';
}
add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );
// rename the coupon field on the checkout page
@maxrice
maxrice / wc-customer-order-csv-export-modify-export-format.php
Created February 2, 2014 04:11
WooCommerce Customer/Order CSV Export - Add additional data to exports
<?php
// add custom column headers
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'lll_group' => 'LLL Group',
'registrant_type' => 'Registrant Type',
'partner_spouse' => 'Partner/Spouse',
// add other column headers here in the format column_key => Column Name
@maxrice
maxrice / wc-customer-order-csv-export-modify-filename-variables.php
Created May 5, 2014 16:57
WooCommerce Customer/Order CSV Export - Add %%order_numbers%% filename variable to support Sequential Order Numbers Pro order numbers in filename :)
<?php
function wc_csv_export_edit_filename( $post_replace_filename, $pre_replace_filename, $order_ids ) {
// only for orders
if ( false !== strpos( $pre_replace_filename, '%%order_numbers%%' ) ) {
$order_numbers = array();
foreach ( $order_ids as $id ) {