Skip to content

Instantly share code, notes, and snippets.

<?php
/**
*
* You can find the complete tutorial for this here:
* https://pluginrepublic.com/woocommerce-custom-fields
*
* Alternatively, check out the plugin
* https://pluginrepublic.com/wordpress-plugins/woocommerce-product-add-ons-ultimate/
*
<?php
function prefix_filter_single_product_classes( $classes, $item ) {
$classes[] = 'my-new-class';
return $classes;
}
add_filter( 'pewc_filter_single_product_classes', 'prefix_filter_single_product_classes', 10, 2 );
/**
* 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;
}
<?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
@plugin-republic
plugin-republic / add-to-wishlist-location.php
Last active July 31, 2020 13:45
Change location of Add to Wishlist button
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 );
<?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' );
@plugin-republic
plugin-republic / wc-order-query.php
Last active October 9, 2018 14:30
Use WC_Order_Query to query WooCommerce orders
<?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 ) {
<?php
$order = wc_get_order( $order_id );
$customer_id = $order->get_user_id();
<?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();