Skip to content

Instantly share code, notes, and snippets.

Gareth Harris plugin-republic

Block or report user

Report or block plugin-republic

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
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 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 popular-posts-shortcode.php
@plugin-republic
plugin-republic / wc-order-query.php
Last active Oct 9, 2018
Use WC_Order_Query to query WooCommerce orders
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 woocommerce-customer-id-from-order.php
<?php
$order = wc_get_order( $order_id );
$customer_id = $order->get_user_id();
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-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 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;
}
@plugin-republic
plugin-republic / get-product-from-subscription.php
Created Nov 5, 2018
How to find the products associated with a WooCommerce subscription
View get-product-from-subscription.php
/**
* How to get the product associated with a WooCommerce subscription
*/
function ct_checkout_subscription_created( $subscription, $order, $recurring_cart ) {
$id = $subscription->get_id(); // You can use this to set meta in the subscription
// Get the products in the order
$items = $order->get_items();
foreach( $items as $item ) {
$product = $item->get_product();
$product_id = $product->get_id();
@plugin-republic
plugin-republic / add-to-wishlist-location.php
Last active Nov 14, 2018
Change location of Add to Wishlist button
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 );
You can’t perform that action at this time.