-
-
Save fervous/fbda9ce3245da6caa555cda212e14d58 to your computer and use it in GitHub Desktop.
WC Vendors Pro - Gift Wrap by Vendors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gives vendors an option to allow gift wrapping. Requires https://wordpress.org/plugins/woocommerce-product-gift-wrap/ | |
// Goes in your product-edit.php template, anywhere you see fit for it | |
WCVendors_Pro_Form_Helper::input( | |
array( | |
'post_id' => $object_id, | |
'id' => 'wcv_custom_product_gift_wrapper_enable', | |
'label' => __( 'Let buyer choose product to be wrapped?', 'wcvendors-pro' ), | |
'type' => 'checkbox' | |
) | |
); | |
WCVendors_Pro_Form_Helper::input( array( | |
'type' => 'text', | |
'post_id' => $object_id, | |
'id' => 'wcv_custom_product_gift_wrap_price', | |
'label' => __( 'Wrapping cost', 'wcvendors-pro' ), | |
'placeholder' => __( '0', 'wcvendors-pro' ), | |
'desc_tip' => 'true', | |
'description' => __( 'Leave blank if wrapping is free.', 'wcvendors-pro' ), | |
) ); | |
// Goes in functions.php | |
/* WC Vendors Pro - Gift Wrap Option */ | |
function wcv_enable_gift_wrap ($post_id) { | |
$wcv_enable_wrap = get_post_meta( $post_id, 'wcv_custom_product_gift_wrapper_enable', true ); | |
$wcv_gift_wrap_cost = get_post_meta( $post_id, 'wcv_custom_product_gift_wrap_price', true ); | |
if ( $wcv_enable_wrap = 'yes' ) { | |
update_post_meta( $post_id, '_is_gift_wrappable', $wcv_enable_wrap ); | |
update_post_meta( $post_id, '_gift_wrap_cost', $wcv_gift_wrap_cost ); | |
} | |
} | |
add_action ('wcv_save_product','wcv_enable_gift_wrap'); | |
That's it! Credit to @had_hc on https://www.wcvendors.com/help/topic/sharing-add-gift-wrapping-option/ for coding this up. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment