Fulfillment latency in single product page
-
Hi to everybody, I want to add to my website a fulfillment latency.
I’ve search for a plugin or for a script along all web and I found a script in https://www.businessbloomer.com that shown how to add checkbox in backend and front end. But I need a textbox so I’ve tired to modify it, but someone was wrong. Someone can help me?// 1. Add FULFILLMENT LATENCY (General tab)
add_action( ‘woocommerce_product_options_general_product_data’, ‘bbloomer_add_badge_checkbox_to_products1’ );
function bbloomer_add_badge_checkbox_to_products1() {
woocommerce_wp_text_input( array(
‘id’ => ‘fulfillment_latency’,
‘placeholder’ => ‘Fulfillment Latency’,
‘label’ => __(‘Fulfillment Latency’, ‘woocommerce’),
‘desc_tip’ => ‘true’
)
);
}// —————————————–
// 2. Save checkbox via custom fieldadd_action( ‘save_post’, ‘bbloomer_save_badge_checkbox_to_post_meta1’ );
function bbloomer_save_badge_checkbox_to_post_meta1( $product_id ) {
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE )
return;
if ( isset( $_POST[‘fulfillment_latency’] ) ) {
update_post_meta( $product_id, ‘fulfillment_latency’, $_POST[‘fulfillment_latency’] );
} else delete_post_meta( $product_id, ‘fulfillment_latency’ );
}// —————————————–
// 3. Display badge @ single product page if checkbox checked
add_action( ‘woocommerce_before_add_to_cart_quantity’, ‘bbloomer_display_badge_if_checkbox’, 16 );function bbloomer_display_badge_if_checkbox() {
global $product;
if ( get_post_meta( $product->get_id(), ‘fulfillment_latency’, true ) ) {
echo ‘
<div class=”woocommerce-message”>Shipping latency:’ .get_field(‘fulfillment_latency’). ‘business days</div>’ ;‘;
}
}
- The topic ‘Fulfillment latency in single product page’ is closed to new replies.