Skip to content

Instantly share code, notes, and snippets.

View SiR-DanieL's full-sized avatar

Nicola Mustone SiR-DanieL

View GitHub Profile
@SiR-DanieL
SiR-DanieL / functions.php
Last active December 22, 2023 16:41
Adding the User Avatar in My Account Page
<?php
/**
* @snippet Adding the User Avatar in My Account Page
* @author Nicola Mustone
* @author_url https://nicolamustone.blog/2014/12/26/add-the-customer-avatar-in-my-account-page-in-storefront/
* @tested-up-to WooCommerce 8.4.X
*/
function nm_myaccount_customer_avatar() {
$current_user = wp_get_current_user();
echo '<div class="myaccount_avatar">' . get_avatar( $current_user->user_email, 128, '', $current_user->display_name ) . '</div>';
.myaccount_avatar {
border-right: 1px solid rgba(0, 0, 0, 0.1);
float: left;
padding-right: 10px;
margin-right: 10px;
width: 139px;
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active December 22, 2023 15:55
Sell in Specific States/Provinces/Regions with WooCommerce
<?php
/**
* @template Sell to Specific States/Provinces/Regions with WooCommerce
* @author Nicola Mustone
* @author_url https://nicolamustone.blog/2014/12/08/sell-in-specific-states-with-woocommerce/
* @tested-up-to WooCommerce 8.4.X
*/
function wc_sell_only_states( $states ) {
$states['US'] = array(
'CA' => __( 'California', 'woocommerce' ),
@SiR-DanieL
SiR-DanieL / taxonomy-wcpv_product_vendors.php
Created December 22, 2023 14:51
Customizing Vendor Shop Pages in WooCommerce: A Step-by-Step Guide
<?php
/**
* @template Custom Product Vendor Catalog Page
* @author Nicola Mustone
* @author_url https://nicolamustone.blog/2014/10/15/show-custom-template-vendor-shop-pages/
* @tested-up-to WooCommerce 8.4.X
*/
defined( 'ABSPATH' ) || exit;
@SiR-DanieL
SiR-DanieL / functions.php
Last active December 21, 2023 00:24
WooCommerce Related Products: What and How to Improve Them
<?php
/**
* @snippet Get Related Products by Attributes
* @author Nicola Mustone
* @author_url https://nicolamustone.blog/2023/12/21/improve-woocommerce-related-products-recommendations/
* @tested-up-to WooCommerce 8.4.X
*/
add_filter( 'woocommerce_related_products', 'nm_realted_products_by_attributes', 10, 3 );
function nm_realted_products_by_attributes( $related_posts, $product_id, $args ) {
$product = wc_get_product( $product_id );
@SiR-DanieL
SiR-DanieL / functions.php
Last active December 8, 2023 16:29
Adding a PDF Catalog for Your Store
<?php
add_action( 'woocommerce_single_product_summary', 'custom_pdf_catalog_download_button' );
function custom_pdf_catalog_download_button() {
return do_shortcode( '[wc-store-catalog-pdf]' );
}
@SiR-DanieL
SiR-DanieL / style.css
Created December 8, 2023 14:20
How to Show the Product Short Description on the Shop Page
li.product .short-description {
text-align: left;
color: #333333;
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active December 8, 2023 14:17
How to Show the Product Short Description on the Shop Page
<?php
add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 6 );
function woo_show_excerpt_shop_page() {
global $product;
echo '<p class="short-description">' . $product->post->post_excerpt . '</p>';
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active December 7, 2023 09:10
Add an Enquiry Form to The My Account Page in WooCommerce
<?php
class WC_Custom_My_Account_Tabs extends WC_Query {
/**
* Adds main filters and actions and inits the endpoints.
*/
public function __construct() {
add_action( 'init', array( $this, 'add_endpoints' ) );
if ( ! is_admin() ) {
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
@SiR-DanieL
SiR-DanieL / functions.php
Created December 7, 2023 06:25
How to Change the Continue Shopping Redirect URL on the Cart
<?php
add_filter( 'woocommerce_continue_shopping_redirect', 'custom_continue_shopping_redirect' );
function custom_continue_shopping_redirect( $default ) {
// Example condition 1: Redirect to Home
if ( /* your condition for Home */ ) {
return home_url(); // Redirects to the Home page
}
// Example condition 2: Redirect to Shop
if ( /* your condition for Shop */ ) {