Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
tdmrhn / blc-2-add-quantity+atc-to-product-cards.php
Created March 28, 2024 07:19
Blocksy 2 Add Quantity + Add to Card button to Product Cards via Content Blocks Element
<?php
// Add this to Content Blocks > Hook > No Condition or Location
// Call it through Customizer > Product Archives > Card Options > Enable Content Block Element > Select the Hook name in drop down
if ( is_product() || is_shop() || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
global $product;
if ( ! $product->is_sold_individually() && 'variable' != $product->product_type && $product->is_purchasable() && $product->is_in_stock() ) {
echo '<div class="dhn-atc-wrap">';
woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) );
echo '<a href="' . esc_url( $product->add_to_cart_url() ) . '" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="' . esc_attr( $product->get_id() ) . '" aria-label="' . esc_attr( sprintf( __( 'Add to cart: %s', 'woocommerce' ), $product->get_name() ) ) . '" aria-describedby="" rel="nofollow">' . esc_html( $p
@tdmrhn
tdmrhn / blocksy-add-ajax-quantity-to-archive-cards.php
Last active July 10, 2024 22:14
Blocksy Add Ajax Quantity to Archive Cards
<?php
add_filter( 'woocommerce_loop_add_to_cart_link', function ( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$class = implode( ' ', array_filter( array(
'button',
'product_type_' . $product->get_type(),
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
) ) );
@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
@tdmrhn
tdmrhn / blc-posts-shortcode-from-query.php
Created May 24, 2024 06:32
Blocksy Posts Shortcode exclude current post from query
<?php
add_filter('blocksy:general:shortcodes:blocksy-posts:args', function ($query_args, $shortcode_args) {
if (is_singular('portfolio')) {
$query_args['post__not_in'] = array(get_the_ID());
}
return $query_args;
}, 10, 2);
@tdmrhn
tdmrhn / woo-get-product-description-from-acf.php
Created May 18, 2024 11:11
Woo Get Product description from ACF
<?php
$product_id = get_field('your_acf_field_name');
if ($product_id) {
$product = wc_get_product($product_id);
if ($product) {
$product_description = $product->get_description();
echo $product_description;
}
}
@tdmrhn
tdmrhn / blc-2-shop-loop-card-custom-quickview-link.php
Created May 17, 2024 07:50
Blocksy 2 Shop Loop Card Custom Quick View Link
@tdmrhn
tdmrhn / dhn-remove-extra-image-sizes.php
Created December 27, 2022 17:13
Wordpress remove extra image sizes
<?php
add_filter( 'intermediate_image_sizes', function ( $sizes ) {
// keep only 'thumbnail', 'medium', 'large'
$targets = ['medium_large', '1536x1536', '2048x2048','shop_thumbnail', 'shop_single', 'shop_catalog', 'woocommerce_thumbnail', 'woocommerce_single', 'woocommerce_gallery_thumbnail'];
foreach($sizes as $size_index=>$size) {
if(in_array($size, $targets)) {
unset($sizes[$size_index]);
}
}
@tdmrhn
tdmrhn / blc-hide-sidebar-for-certain-categories.php
Created February 4, 2023 08:27
Blocksy Hide Sidebar for Certain Categories
<?php
add_filter('blocksy:general:sidebar-position', function ($current_value) {
if ( is_category( array('places','beach') ) ) {
return 'none';
}
});