Skip to content

Instantly share code, notes, and snippets.

View full-sized avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / disable_coupon_field_on_cart_checkout.php
Last active September 26, 2023 09:21
1. Remove Coupon Field from Cart and Checkout WooCommerce 2. Remove coupon field conditionally https://wpsites.net/product/remove-coupon-field-if-total-is-zero/
View disable_coupon_field_on_cart_checkout.php
add_filter( 'woocommerce_coupons_enabled', 'disable_coupon_field_on_cart_checkout' );
function disable_coupon_field_on_cart_checkout( $enabled ) {
if ( is_cart() || is_checkout() ) {
$enabled = false;
}
return $enabled;
@braddalton
braddalton / Redirect to Order Received Page After Sumup Payment.php
Created September 22, 2023 09:23
Redirect to Order Received Page After Sumup Payment
View Redirect to Order Received Page After Sumup Payment.php
add_action( 'template_redirect', 'sumup_redirect_order_received');
function sumup_redirect_order_received(){
if ( is_wc_endpoint_url( 'order-received' ) ) {
global $wp;
$order_id = intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
$order = wc_get_order( $order_id );
@braddalton
braddalton / woocommerce_different_tax_rate_user_role.php
Last active September 21, 2023 12:02
Different Tax Rate Based on User Role WooCommerce https://wpsites.net/?p=113294
View woocommerce_different_tax_rate_user_role.php
add_filter( 'woocommerce_product_get_tax_class', 'woocommerce_different_tax_rate_user_role', 1, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', 'woocommerce_different_tax_rate_user_role', 1, 2 );
function woocommerce_different_tax_rate_user_role( $tax_class, $product ) {
$user_id = get_current_user_id();
$user = get_user_by( 'id', $user_id );
if ( is_user_logged_in() && ! empty( $user ) && in_array( 'customer-tax-exempt', $user->roles ) ) {
$tax_class = 'zero-rate';
View shortcode for product tags.php
add_shortcode('product_tags', 'product_tags_per_product' );
function product_tags_per_product() {
global $product;
return '<div class="product-tags">' . wc_get_product_tag_list( $product->get_id(), ', ' ) . '</div>';
}
@braddalton
braddalton / hide_out_of_stock_exclude_category.php
Created September 17, 2023 13:58
Hide OOS Exclude Category Woocommerce
View hide_out_of_stock_exclude_category.php
add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'hide_out_of_stock_exclude_category' );
function hide_out_of_stock_exclude_category( $hide ) {
if ( is_product_category( 'fashion' ) ) {
$hide = 'no';
}
return $hide;
}
@braddalton
braddalton / wc-custom-archive-template.php
Last active September 15, 2023 11:56
Step 1 of 3 How To Modify Archive Templates in WooCommerce https://wpsites.net/?p=113143
View wc-custom-archive-template.php
add_filter( 'template_include', 'custom_product_cat_template', 99 );
function custom_product_cat_template( $template ) {
if ( is_product_category('shoes') ) {
$new_template = locate_template( array( 'custom-archive.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
@braddalton
braddalton / Var Dump Single Product Page Data Keys, Values.php
Last active September 15, 2023 18:12
Print Single Product Page Data Keys, Values and json https://wpsites.net/?p=113136
View Var Dump Single Product Page Data Keys, Values.php
add_action( 'loop_start','get_single_product_page_data' );
function get_single_product_page_data() {
if ( ! is_product() )
return;
$product = wc_get_product( get_the_ID() );
$data = $product->get_data();
@braddalton
braddalton / woocommerce_thankyou_page_data.js
Last active September 12, 2023 06:43
WooCommerce Get Thank You Page Data from Product ID https://wpsites.net/?p=113042
View woocommerce_thankyou_page_data.js
<script type="text/javascript">
jQuery(document).ready(function($) {
var order_id = {
"id": 111568,
"parent_id": 0,
"status": "processing",
"currency": "USD",
"version": "8.0.3",
"prices_include_tax": false,
"date_created": {
@braddalton
braddalton / woocommerce_product_backorders_allowed.php
Created September 11, 2023 20:21
woocommerce_product_backorders_allowed user role based
View woocommerce_product_backorders_allowed.php
add_filter( 'woocommerce_product_backorders_allowed', 'woocommerce_product_backorders_allowed', 10, 3 );
function woocommerce_product_backorders_allowed( $backorder_allowed, $product_id, $product ){
if ( current_user_can('wholesaler') ) {
$backorder_allowed = true;
} else {
$backorder_allowed = false;
}
return $backorder_allowed;
}
@braddalton
braddalton / child-category-template.php
Last active August 13, 2023 15:53
Load Custom Sub or Child Category Template for WooCommerce https://wpsites.net/?p=112560
View child-category-template.php
add_filter( 'category_template', 'custom_subcategory_template' );
function custom_subcategory_template( $template ) {
$cat = get_queried_object();
if ( isset( $cat ) && $cat->category_parent ) {
$template = locate_template( 'sub-category.php' );
}