Skip to content

Instantly share code, notes, and snippets.

View gvgvgvijayan's full-sized avatar

Vijayan gvgvgvijayan

View GitHub Profile
@gvgvgvijayan
gvgvgvijayan / functions.php
Created February 1, 2020 11:22
To detect rendered template in WordPress
<?php
add_action('wp_head', function () {
global $template;
echo $template;
});
@gvgvgvijayan
gvgvgvijayan / archive-product.php
Created February 1, 2020 13:49
The snippet to explain overriding WooCommerce template. Website: www.vijayan.in
<header class="woocommerce-products-header">
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
<h1 class="woocommerce-products-header__title page-title"><?php echo strtoupper(woocommerce_page_title(false)); ?></h1>
<?php endif; ?>
<?php
/**
* Hook: woocommerce_archive_description.
*
* @hooked woocommerce_taxonomy_archive_description - 10
@gvgvgvijayan
gvgvgvijayan / vg-woo-sort.php
Created March 15, 2020 08:31
This is core script for custom sort for WooCommerce Shop. This snippet is used for explaining the tutorial: www.vijayan.in/woocommerce-custom-product-sorting
<?php
defined( 'ABSPATH' ) or die( 'No direct access please!' );
/*
Plugin Name: VG Woo Sort
Description: Aditional sort for WooCommerce Shop
Version: 1.0
Author: Vijayan G
Author URI: www.vijayan.in
*/
@gvgvgvijayan
gvgvgvijayan / orderby.php
Created March 15, 2020 09:02
This is template script for custom sort for WooCommerce Shop. This snippet is used for explaining the tutorial: www.vijayan.in/woocommerce-custom-product-sorting
<?php
/**
* Show options for ordering
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/orderby.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@gvgvgvijayan
gvgvgvijayan / no-direct-access.php
Last active March 15, 2020 11:47
WordPress plugin access security
<?php
defined( 'ABSPATH' ) or die( 'No direct access please!' );
/*
Plugin Name: VG Woo Sort
Description: Aditional sort for WooCommerce Shop
Version: 1.0
Author: Vijayan G
Author URI: www.vijayan.in
*/
/*
Plugin Name: VG Woo Sort
Description: Aditional sort for WooCommerce Shop
Version: 1.0
Author: Vijayan G
Author URI: www.vijayan.in
*/
<?php
/**
* Callback method to implement A-Z & Z-A sort functionality
*
* @since 1.0
*/
public function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ?
wc_clean( $_GET['orderby'] ) :
apply_filters( 'woocommerce_default_catalog_orderby',
<?php
public function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby = [
'menu_order' => __( 'Default', 'woocommerce'),
'alpha_list' => __('A - Z', 'woocommerce'),
'reverse_list' => __( 'Z - A', 'woocommerce'),
'popularity' => __( 'Popularity', 'woocommerce' ),
'rating' => __( 'Average rating', 'woocommerce' ),
'date' => __( 'Latest', 'woocommerce' ),
'price' => __( 'Price: low to high', 'woocommerce' ),
<?php
add_filter( 'woocommerce_get_catalog_ordering_args', array('VG_Sort', 'custom_woocommerce_get_catalog_ordering_args' ));
add_filter( 'woocommerce_default_catalog_orderby_options', array('VG_Sort', 'custom_woocommerce_catalog_orderby' ));
add_filter( 'woocommerce_catalog_orderby', array('VG_Sort', 'custom_woocommerce_catalog_orderby' ));