Skip to content

Instantly share code, notes, and snippets.

@pvphong90
pvphong90 / gist:61efddb1be0a5d690cb10afa325df02b
Created February 19, 2019 08:20
WOOCOMMERCE QUANTITY SELECT FIELD
<?php
/**
* Product quantity inputs
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@pvphong90
pvphong90 / phantrang.php
Created November 24, 2018 07:01
Code phân trang wordpress
function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
$pages = paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'type' => 'array',
@pvphong90
pvphong90 / funtion.php
Created October 28, 2018 08:00
Hiển thị bộ lọc bài viết bởi Taxonomies trong admin Wordpress
<?php
function filter_cars_by_taxonomies( $post_type, $which ) {
// Apply this only on a specific post type
if ( 'car' !== $post_type )
return;
// A list of taxonomy slugs to filter by
$taxonomies = array( 'manufacturer', 'model', 'transmission', 'doors', 'color' );
@pvphong90
pvphong90 / remove_filter.php
Last active September 20, 2018 09:19
Bỏ đi bộ lọc sản phẩm
// Tùy chỉnh các tùy chọn sắp xếp sản phẩm WooCommerce
// Tùy chọn có sẵn là: menu_order, xếp hạng, ngày, mức độ phổ biến, giá, giá-desc
function custom_woocommerce_product_sorting( $orderby ) {
// The following removes the rating, date, and the popularity sorting options;
// feel free to customize and enable/disable the options as needed.
unset($orderby["rating"]);
unset($orderby["date"]);
unset($orderby["popularity"]);
return $orderby;
}
@pvphong90
pvphong90 / get_order.php
Created September 20, 2018 08:46
Code lấy ra bộ lọc của Woo
<ul>
<li class="gia_khac">Sắp xếp <i class="icon-angle-down"></i>
<ul class="dropdown woocommerce-ordering">
<?php
$catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),
add_filter( 'the_content', 'add_related_post' );
function add_related_post( $content ) {
$related_posts= "<div class='meta-related'>".do_shortcode('[related_posts]')."</div>";
if ( is_single() ) {
return count_p( $related_posts, 2, $content );
}
return $content;
}
function count_p( $insertion, $paragraph_id, $content ) {
$end_p = '</p>';
$paragraphs = explode( $end_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $end_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
function create_shortcode_related_posts($args, $content) {
ob_start(); ?>
<?php
$tags = wp_get_post_terms( get_queried_object_id(), 'category', array('fields' => 'ids') );
$args = array (
'post__not_in' => array ( get_queried_object_id() ),
'posts_per_page' => 5,
'orderby' => 'rand',
'tax_query' => array (
array(
@pvphong90
pvphong90 / function.php
Created November 3, 2017 07:10
Tùy chỉnh độ dài của chữ
function custom_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'custom_excerpt_length');
@pvphong90
pvphong90 / function.php
Created November 3, 2017 07:09
Để tùy chỉnh [...] sau khi trích đoạn bài, bạn có thể đặt mã sau trong functions.php:
function excerpt_read_more( $more ){
return '<a href="' . get_permalink() . '" rel="nofollow"> Read More</a>';
add_filter( 'excerpt_more', 'excerpt_read_more' );
}