Skip to content

Instantly share code, notes, and snippets.

@sonipb
sonipb / wc-custom-sorting-options-asc-dec.php
Last active August 12, 2018 08:50 — forked from woogists/wc-custom-sorting-options-asc-dec.php
[Frontend Snippets] Custom sorting options to random (asc/desc)
/**
* Add custom sorting options (asc/desc)
*/
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'random_list' == $orderby_value ) {
$args['orderby'] = 'rand';
$args['order'] = '';
$args['meta_key'] = '';
@sonipb
sonipb / sale-flash.php
Created June 21, 2018 11:42 — forked from vividvilla/sale-flash.php
Display Discount/Offer percentage in WooCommerce
<?php
/**
* Product loop sale flash
*
* @author Vivek R @ WPSTuffs.com
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@sonipb
sonipb / woo-email.php
Created February 3, 2018 11:20 — forked from goranefbl/woo-email.php
Use woocommerce email template header/footer with your plugin
public function gens_send_email($user_id,$coupon_code) {
if ( !$user_id || !$coupon_code) {
return false;
}
global $woocommerce;
$mailer = $woocommerce->mailer();
$user_info = get_userdata($user_id);
// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' );
get_option( 'woocommerce_cart_page_id' );
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' );
get_option( 'woocommerce_thanks_page_id' );
get_option( 'woocommerce_myaccount_page_id' );
get_option( 'woocommerce_edit_address_page_id' );
get_option( 'woocommerce_view_order_page_id' );
get_option( 'woocommerce_terms_page_id' );
@sonipb
sonipb / functions.php
Created October 1, 2017 08:09 — forked from corsonr/functions.php
Display WooCommerce product variations dropdown select on the shop page
<?php
// Display variations dropdowns on shop page for variable products
add_filter( 'woocommerce_loop_add_to_cart_link', 'woo_display_variation_dropdown_on_shop_page' );
function woo_display_variation_dropdown_on_shop_page() {
global $product;
if( $product->is_type( 'variable' )) {
@sonipb
sonipb / gist:938b9651f3289b499741269506d2ca9b
Created September 27, 2017 04:04 — forked from slash1andy/gist:970f81db419eb01c9761
WooCommerce Redirect to Custom URL Based on Product Purchased
function wcs_redirect_product_based ( $order_id ){
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
$_product = wc_get_product( $item['product_id'] );
// Add whatever product id you want below here
if ( $item['product_id'] == 70 ) {
// change below to the URL that you want to send your customer to
wp_redirect('http://www.yoururl.com/your-thank-you-page');
}
@sonipb
sonipb / lgbk_add_member.php
Created September 26, 2017 14:06 — forked from troydean/lgbk_add_member.php
WooCommerce Change User Role on Purchase of Specific Product
function lgbk_add_member( $order_id ) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
}
<?php
function email_past_due() {
global $wpdb;
$mailer = WC_Emails::instance();
$date = date( "Y-m-d H:i:s", current_time( 'timestamp' ) + 86400 * 7 );
$due_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
@sonipb
sonipb / my_pmpro_confirmation_redirect.php
Created August 1, 2017 07:52 — forked from strangerstudios/my_pmpro_confirmation_redirect.php
Redirect Paid Memberships Pro Confirmation to Another Page Based on Level
/*
This code will redirect users from the default PMPro confirmation page to a specific page depending on their level.
Set the confirmation_pages array. Array keys should be membership level ids and the values are the page ids. So array(1=>2) will redirect membership level with id = 1 to the page with id = 2.
*/
function my_pmpro_confirmation_redirect()
{
$confirmation_pages = array(1 => 2); //change this use your membership level ids and page ids
global $pmpro_pages;
@sonipb
sonipb / att.html
Created July 11, 2017 06:01 — forked from igorbenic/att.html
Extending the WordPress Media Uploader: Custom Fields | http://www.ibenic.com/extending-wordpress-media-uploader-custom-fields
<input type="text" name="attachments[123][field_name]" />