Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Dalton braddalton

View GitHub Profile
@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>';
}
@braddalton
braddalton / custom-field-before-shop-loop
Created May 19, 2022
PHP code to add content before your single product on any shop loop archive page type https://wpsites.net/?p=109784
View custom-field-before-shop-loop
add_action( 'woocommerce_before_shop_loop_item_title', 'hook_before_product', 2 );
function hook_before_product() {
echo '<p class="before-product">' . get_post_meta( get_the_ID(), 'before_product', true ) . '</p>';
}
@braddalton
braddalton / custom-field-after-single-product
Created May 19, 2022
PHP code to add content after your single product on the single product page
View custom-field-after-single-product
add_action( 'woocommerce_product_meta_end', 'hook_after_product', 22 );
function hook_after_product() {
echo '<p class="after-product">' . get_post_meta( get_the_ID(), 'after_product', true ) . '</p>';
}
@braddalton
braddalton / custom-field-before-single-product.php
Created May 19, 2022
PHP code to add content before your single product on the single product page https://wpsites.net/?p=109784
View custom-field-before-single-product.php
add_action( 'woocommerce_single_product_summary', 'hook_before_product', 2 );
function hook_before_product() {
echo '<p class="before-product">' . get_post_meta( get_the_ID(), 'before_product', true ) . '</p>';
}
View WooCommerce WP_Query 1 product category.php
$args = array(
'post_type' => 'product',
'orderby' => 'rand',
'product_cat' => 'clothing',
'posts_per_page' => 3
);
View WooCommerce WP_Query orderby rand.php
$args = array(
'post_type' => 'product',
'orderby' => 'rand',
'posts_per_page' => 3
);
View wc-product-query-parameters
'name' => '',
'parent' => '',
'parent_exclude' => '',
'exclude' => '',
'page' => 1,
'offset' => '',
'paginate' => false,
'order' => 'DESC',
'orderby' => 'date',
'return' => 'objects',
@braddalton
braddalton / functions.php
Last active May 17, 2022
Submit Button Text for WooCommerce Product Reviews https://wpsites.net/?p=109670
View functions.php
add_action( 'comment_form', 'add_comment_notice', 888 );
function add_comment_notice() {
if ( ! is_product() ) {
return;
}
?><p class="submit-reviews-notice"><?php esc_html_e( 'Might take 10 - 20 seconds after clicking Submit.', 'woocommerce' ); ?></p><?php
}
@braddalton
braddalton / functions.php
Last active May 17, 2022
Remove Current Single Product From WooCommerce Shortcode Products https://wpsites.net/?p=109648
View functions.php
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_remove_current_product' );
function woocommerce_shortcode_products_remove_current_product( $args ) {
$args['post__not_in'] = array( get_the_ID() );
return $args;
}