Modify/Create a WordPress/WooCommerce Filter to add Text Over Image
£10-20 GBP
Pagado a la entrega
Hey guys,
We are using a filter in our [login to view URL] file that adds a 'pre-order now' badge over the top of images on the [login to view URL] page. Works fantastic, however, we need it modified so that it shows the same badge over images on the store archive page.
Examples
This product has the pre-order now badge: [login to view URL]
This is the shop archive page, the badge doesnt show over the top left hand product image. We want it to show the 'pre-order now' badge like the single product page above: [login to view URL]
We would like our hook/filter modified so that we don't have to go editing other files needlessly. I have included the exact piece of code that adds this badge below.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'vas_custom_cart_button_text' ); // < 2.1
add_filter( 'woocommerce_product_add_to_cart_text', 'vas_custom_cart_button_text' ); // < 2.1
function vas_custom_cart_button_text() {
global $product;
$preorder = get_post_meta( $product->id, '_wc_pre_orders_enabled', true );
if($preorder==false|| strtolower($preorder)!='yes')
{
$btn = 'Add to Cart';
}else{
$btn = 'Pre-Order Now';
}
return __( $btn, 'woocommerce' );
}
function vas_woocommerce_single_product_image_html( $sprintf, $post_id ) {
// make filter magic happen here...
$preorder = get_post_meta( $post_id, '_wc_pre_orders_enabled', true );
if($preorder==false|| strtolower($preorder)!='yes')
return $sprintf;
return '<span class="onsale is_pre">' . __( 'Pre-Order Now', 'woocommerce' ) . '</span>'. $sprintf;
};
add_filter( 'woocommerce_single_product_image_html', 'vas_woocommerce_single_product_image_html', 10, 2 );
Nº del proyecto: #11349101