Skip to content

Instantly share code, notes, and snippets.

@webaware
Last active September 27, 2015 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webaware/1fe598e60f9ad9a912ee to your computer and use it in GitHub Desktop.
Save webaware/1fe598e60f9ad9a912ee to your computer and use it in GitHub Desktop.
Extend an Order Form for WooCommerce form with WordPress hooks, instead of hacking templates. Requires version 1.4.0 or higher. Save this file as a simple plugin in the WordPress plugins folder. http://orderform-woo.webaware.net.au/
<?php
/*
Plugin Name: Order Form for WooCommerce extend form
Plugin URI: https://gist.github.com/webaware/1fe598e60f9ad9a912ee
Description: example form extras using hooks
Author: WebAware
Author URI: http://webaware.com.au/
*/
/**
* show the submit/clear buttons at the top of the form too
*/
add_action('orderform_woocommerce_form_start', function($attrs) {
?>
<p style="clear:both">
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html($attrs['submittitle']); ?></button>
<button style="display:none" class="single_add_to_cart_button button alt" name="clear-form"><?php echo esc_html($attrs['cleartitle']); ?></button>
</p>
<?php
});
/**
* insert a column before Price -- table header
* change the text to the column heading you want
*/
add_action('orderform_woocommerce_before_order_price_head', function($attrs) {
?>
<th class="your-custom-column-class">Custom</th>
<?php
});
/**
* insert a column before Price -- table footer
* this shows just a blank cell, but you can put whatever you want there
*/
add_action('orderform_woocommerce_before_order_price_foot', function($attrs) {
?>
<td class="your-custom-column-class">&nbsp;</td>
<?php
});
/**
* insert a column before Price -- table body
* e.g. get other WooCommerce product data and show it here
*/
add_action('orderform_woocommerce_before_order_price', function($product, $attrs) {
$stock = $product->get_total_stock();
?>
<td class="your-custom-column-class"><?php echo number_format($stock); ?></td>
<?php
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment