Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Dalton braddalton

View GitHub Profile
View Add product date WooCommerce
add_action( 'woocommerce_single_product_summary', 'add_product_date', 25 );
function add_product_date() {
if ( is_product() && ! empty( get_post_meta( get_the_ID(), 'product_date', true ) ) ) {
echo do_shortcode('[post_date]');
}
}
@braddalton
braddalton / remove setup header
Last active Jun 23, 2022
Remove WooCommerce Product Admin Header https://wpsites.net/?p=110512
View remove setup header
add_action( 'admin_init', 'remove_setup_header' );
function remove_setup_header() {
echo '<style>#wpadminbar + #wpbody { margin-top:0; }</style>';
}
remove_action( 'in_admin_header', array( 'Automattic\WooCommerce\Internal\Admin\Loader', 'embed_page_header' ) );
View remove woocommerce star rating
add_action( 'woocommerce_before_single_product_summary', 'remove_single_rating' );
function remove_single_rating() {
if ( ! empty ( get_post_meta( get_the_ID(), 'remove_rating', true ) ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
}
}
@braddalton
braddalton / style.css
Created Jun 16, 2022
WooCommerce Single Product Quantity Discount https://wpsites.net/?p=110494
View style.css
@media only screen and (min-width: 960px) {
.cart-quantity-discount {
display: inline;
color: white;
font-weight: 500;
font-size: 12px;
background: green;
padding-top: 1px;
padding-bottom: 1px;
@braddalton
braddalton / cart.php
Last active Jun 11, 2022
WooCommerce Remove Coupon Form From Cart https://wpsites.net/?p=110461
View cart.php
<?php
/**
* Cart Page
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cart.php.
*
* @author Brad Dalton - WP SITES
* @link https://wpsites.net/?p=110461
*/
View Add Custom Subscriber Customer Capabilities WooCommerce
add_action( 'admin_init', 'add_subscriber_capabilities');
function add_subscriber_capabilities() {
$role = get_role( 'subscriber' );
$role->add_cap( 'edit_posts' );
$role->add_cap( 'edit_published_posts' );
$role->add_cap( 'publish_posts' );
$role->add_cap( 'delete_posts' );
$role->add_cap( 'delete_published_posts' );
View add-custom-role-customer-woocommerce
add_action( 'admin_init', 'add_customer_user_role' );
function add_customer_user_role() {
add_role(
'customer',
__( 'Customer - Expired Subscriber' ),
array(
'read' => true,
));
@braddalton
braddalton / remove-related-products-woocommerce
Last active May 23, 2022
WooCommerce Remove Related Products Per Single Product https://wpsites.net/?p=109833
View remove-related-products-woocommerce
@braddalton
braddalton / woocommerce-archive-page-custom-field
Created May 20, 2022
PHP code to add content before your product taxonomy archive title on any taxonomy term archive page type https://wpsites.net/?p=109784
View woocommerce-archive-page-custom-field
add_action( 'woocommerce_before_main_content', 'taxonomy_page_custom_field', 99 );
function taxonomy_page_custom_field() {
if ( is_product_taxonomy() ) {
$field = get_woocommerce_term_meta( get_queried_object_id(), 'wc_taxonomy_custom_field', true );
if ( get_queried_object() && ! empty( $field ) ) {
echo '<p class="taxonomy-custom-field">' . $field . '</p>';
@braddalton
braddalton / custom-field-after-shop-loop
Created May 19, 2022
Use this code to add content after your single product on any shop loop archive page type. https://wpsites.net/?p=109784
View custom-field-after-shop-loop
add_action( 'woocommerce_after_shop_loop_item_title', 'hook_after_product', 2 );
function hook_after_product() {
echo '<p class="after-product">' . get_post_meta( get_the_ID(), 'after_product', true ) . '</p>';
}