Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
tdmrhn / blc-change-single-product-image-zoom-icon.css
Created September 23, 2024 16:17
Blocksy Single Product Gallery Change Zoom Icon
.woocommerce-product-gallery__trigger::before {
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-6 -6 30 30'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0'/%3E%3C/svg%3E%0A");
}
@tdmrhn
tdmrhn / blc-pte-filters-mobile-horizontal-scroll.css
Created September 23, 2024 05:52
Blocksy PTE Filters Mobile Horizontal Scrolling
@media only screen and (max-width: 700px) {
.ct-dynamic-filter {
overflow-x: scroll;
flex-wrap: nowrap;
justify-content: left;
padding-bottom: 1rem;
}
.ct-dynamic-filter > * {
flex: 0 0 auto;
@tdmrhn
tdmrhn / blc-2-variation-swatches-container-overflow-slide.css
Created September 19, 2024 09:14
Blocksy 2 Card Variation Swatches Overflow Slide
.ct-card-variation-swatches .variations { align-items: center; }
.ct-card-variation-swatches .ct-variation-swatches {
overflow-x: auto;
scrollbar-width: thin;
padding-bottom: 10px;
justify-content: flex-start;
flex-wrap: nowrap;
max-width: 80%;
}
@tdmrhn
tdmrhn / blc-2-add-custom-hook-before-last-3rd-block.php
Created September 7, 2024 10:41
Blocksy 2 Add Custom Hook to Single Posts Before Last 3rd Block
<?php
add_filter( 'the_content', function ( $content ) {
if ( is_single() ) {
$blocks = parse_blocks( $content );
$block_count = count( $blocks );
$insert_before_block = 3;
$custom_hook_content = apply_filters( 'blocksy:before:certain:last:block', '' );
if ( $block_count >= $insert_before_block ) {
@tdmrhn
tdmrhn / wp-show-sticky-posts-first-in-category.php
Created August 20, 2024 21:31
WP Show Sticky Posts First In Category Query
<?php
add_action('pre_get_posts', function($query) {
if ($query->is_main_query() && !is_admin() && $query->is_category()) {
$sticky_posts = get_option('sticky_posts');
if ($sticky_posts) {
$cat_id = get_queried_object_id();
$sticky_query = new WP_Query([
'post__in' => $sticky_posts,
'cat' => $cat_id,
'posts_per_page' => -1,
@tdmrhn
tdmrhn / woo-show-best-seller-products-empty-categories.php
Created August 13, 2024 13:23
Show Best Seller Products in Empty Woo Categories
<?php
// https://woocommerce.github.io/code-reference/files/woocommerce-templates-archive-product.html
add_action('woocommerce_no_products_found', function () {
// Display the bestsellers
echo '<h2>Our Bestsellers</h2>';
echo do_shortcode('[best_selling_products per_page="6" columns="3"]'); // https://woocommerce.com/document/woocommerce-shortcodes/products/
// Display a button to go to the shop page
echo '<div class="ct-container">';
echo '<a class="ct-button" href="' . esc_url(get_permalink(wc_get_page_id('shop'))) . '">All Products</a>';
@tdmrhn
tdmrhn / blc-2-single-post-comments-2-columns.css
Created August 9, 2024 18:43
Blocksy 2 Single Post Comments 2 Columns
@media (min-width: 1000px) {
.ct-comments { display: grid; grid-template-columns: repeat(2, 1fr); column-gap: 5vw }
.ct-comments > h3 { grid-column: span 2; }
}
@tdmrhn
tdmrhn / blc-posts-shortcode-add-years-arg.php
Created July 4, 2024 07:36
Blocksy Posts Shortcode Add Years arg
<?php
add_filter('blocksy:general:shortcodes:blocksy-posts:args', function ($query_args, $shortcode_args) {
if (isset($shortcode_args['years'])) {
$years = array_map('intval', explode(',', $shortcode_args['years']));
$query_args['date_query'] = array(
'relation' => 'OR',
array_map(function ($year) {
return array('year' => $year);
}, $years)
);
@tdmrhn
tdmrhn / blc-2-woo-single-gallery-mobile-resize.css
Created June 7, 2024 09:42
Blocksy 2 Woo Single Gallery and Thumbnails resize
@tdmrhn
tdmrhn / blc-2-echo-content-block-product-attribute-term.php
Created June 2, 2024 15:10
Blocksy 2 Content Blocks Hook + Product Attribute (and term)
<?php
// Change the hook as you want
// Remove "//"s if you want to check the color attribute specific term
add_action( 'woocommerce_product_meta_end', function () {
global $product;
$attributes = $product->get_attributes();
if ( isset( $attributes['pa_color'] ) ) {
// $color_terms = wc_get_product_terms( $product->get_id(), 'pa_color', array( 'fields' => 'names' ) );
// if ( in_array( 'Red', $color_terms ) ) { // Check if 'Red' is one of the terms