Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Dalton braddalton

View GitHub Profile
View author pro books archive page template
function genesis_author_pro_book_author(){
global $Genesis_Author_Pro_CPT;
$terms = wp_get_post_terms( get_the_ID(), $Genesis_Author_Pro_CPT->author );
if ( empty( $terms ) || is_wp_error( $terms ) ){
return;
}
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]');
}
}
View functions.php
function default_category_featured_image() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
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 / 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' ) );
@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 functions.php
add_action ( 'genesis_entry_footer', 'popular_posts_after_content' );
function popular_posts_after_content() {
if ( is_singular('post') ) {
get_template_part( 'wpsites' );
}}
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,
));