Instantly share code, notes, and snippets.

View woocommerce-is-purchasable.php
<?php
/**
* Prevent products being purchased from archive
* @return Boolean
*/
function pewc_filter_is_purchasable( $is_purchasable, $product ) {
if( is_archive() ) {
return false;
}
return $is_purchasable;
View billing-details-from-wc-order.php
<?php
$order = wc_get_order( $order_id );
echo $order->get_billing_email();
echo $order->get_billing_first_name();
echo $order->get_billing_last_name();
echo $order->get_billing_address_1();
echo $order->get_billing_address_2();
echo $order->get_billing_postcode();
echo $order->get_billing_state();
echo $order->get_billing_country();
View woocommerce-customer-id-from-order.php
<?php
$order = wc_get_order( $order_id );
$customer_id = $order->get_user_id();
View wc-order-query.php
<?php
$args = array(
'limit' => 9999,
'return' => 'ids',
'date_completed' => '2018-10-01...2018-10-10',
'status' => 'completed'
);
$query = new WC_Order_Query( $args );
$orders = $query->get_orders();
foreach( $orders as $order_id ) {
View popular-posts-shortcode.php
View filter-mime-types.php
function my_prefix_upload_mimes( $mimes ) {
// Add PhotoShop PSD files to list of permitted WordPress mime types
$mimes['psd'] = "application/x-photoshop";
return $mimes;
}
add_filter( 'upload_mimes', 'my_prefix_upload_mimes' );
View add-to-wishlist-location.php
function prefix_wishlist_template_location( $template_hook, $product_id ) {
// Return your hook here
return 'woocommerce_single_product_summary';
}
add_filter( 'woocommerce_wishlists_template_location', 'prefix_wishlist_template_location', 10, 2 );
View checkbox_input.php
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty
View override-woocommerce-template-plugin.php
/**
* Filter the cart template path to use our cart.php template instead of the theme's
*/
function csp_locate_template( $template, $template_name, $template_path ) {
$basename = basename( $template );
if( $basename == 'cart.php' ) {
$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'templates/cart.php';
}
return $template;
}
View custom-fields-for-woocommerce.php
<?php
/**
* Plugin Name: Custom Fields for WooCommerce
* Description: Add custom fields to WooCommerce products
* Version: 1.0.0
* Author: Gareth Harris
* Author URI: https://catapultthemes.com/
* Text Domain: cfwc
* WC requires at least: 3.4.0
* WC tested up to: 3.4.2