Skip to content

Instantly share code, notes, and snippets.

Dave Dean Deaner666

Block or report user

Report or block Deaner666

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Deaner666
Deaner666 / functions.php
Created Nov 14, 2015
Display the details meta field on a WooCommerce product_cat term archive
View functions.php
<?php
add_action( 'woocommerce_after_shop_loop', 'wpm_product_cat_display_details_meta' );
/**
* Display details meta on Product Category archives.
*
*/
function wpm_product_cat_display_details_meta() {
if ( ! is_tax( 'product_cat' ) ) {
@Deaner666
Deaner666 / functions.php
Created Nov 14, 2015
Save the WooCommerce product_cat details meta field passed by the add or edit category page
View functions.php
<?php
add_action( 'create_product_cat', 'wpm_product_cat_details_meta_save' );
add_action( 'edit_product_cat', 'wpm_product_cat_details_meta_save' );
/**
* Save Product Category details meta.
*
* Save the product_cat details meta POSTed from the
* edit product_cat page or the add product_cat page.
*
@Deaner666
Deaner666 / functions.php
Last active Nov 13, 2015
Add a text area for details meta on a WooCommerce product category edit term page
View functions.php
<?php
add_action( 'product_cat_edit_form_fields', 'wpm_product_cat_edit_details_meta' );
/**
* Add a details metabox to the Edit Product Category page.
*
* For adding a details metabox to the WordPress admin when
* editing an existing product category in WooCommerce.
*
* @param object $term The existing term object.
@Deaner666
Deaner666 / functions.php
Last active Nov 13, 2015
Add a textarea for the details meta field on WooCommerce product category terms
View functions.php
<?php
add_action( 'product_cat_add_form_fields', 'wpm_product_cat_add_details_meta' );
/**
* Add a details metabox to the Add New Product Category page.
*
* For adding a details metabox to the WordPress admin when
* creating new product categories in WooCommerce.
*
*/
@Deaner666
Deaner666 / functions.php
Created Nov 13, 2015
Register "details" meta field on WooCommerce product_cat terms
View functions.php
<?php
add_action( 'init', 'wpm_product_cat_register_meta' );
/**
* Register details product_cat meta.
*
* Register the details metabox for WooCommerce product categories.
*
*/
function wpm_product_cat_register_meta() {
@Deaner666
Deaner666 / functions.php
Created May 27, 2015
Pre-populate Ninja Forms fields from URL parameters
View functions.php
<?php
add_filter( 'ninja_forms_field', 'wpm_handle_http_query_string' );
function wpm_handle_http_query_string( $data ) {
// A list field with label "Tier"
if($data['label']=='Tier' && get_query_var('tier')) {
foreach ($data['list']['options'] as $key => $value) {
if($value['value'] == get_query_var('tier')) {
$data['list']['options'][$key]['selected'] = 1;
@Deaner666
Deaner666 / functions.php
Last active Aug 29, 2015
Pre-populate a Ninja Forms Tier field from a URL parameter
View functions.php
<?php
add_filter( 'ninja_forms_field', 'wpm_handle_http_query_string' );
function wpm_handle_http_query_string( $data ) {
if($data['label']=='Tier' && get_query_var('tier')) {
foreach ($data['list']['options'] as $key => $value) {
if($value['value'] == get_query_var('tier')) {
$data['list']['options'][$key]['selected'] = 1;
}
@Deaner666
Deaner666 / functions.php
Last active Aug 29, 2015
Declare custom URL parameters in WordPress
View functions.php
<?php
// Declare custom URL parameters
add_filter( 'query_vars', 'wpm_add_query_vars_filter' );
function wpm_add_query_vars_filter( $vars ) {
$vars[] = "tier";
$vars[] = "second-param";
$vars[] = "third-param"; // etc.
return $vars;
}
View fencing-lessons.php
<div class="tier1">
<h2>Lackey</h2>
// ...
// ... Tier 1 description here
// ...
<a href="enquiry-form.php?tier=lackey">Join now</a>
@Deaner666
Deaner666 / page.php
Created May 26, 2015
Outputting a URL parameter in PHP
View page.php
<?php
if ( isset($_GET['key']) ) {
echo $_GET['key'];
} else {
// Fallback behaviour here
}
You can’t perform that action at this time.