Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Last active September 3, 2016 04:17
Show Gist options
  • Save bentasm1/b55ed2807c64d8954fb4 to your computer and use it in GitHub Desktop.
Save bentasm1/b55ed2807c64d8954fb4 to your computer and use it in GitHub Desktop.
WC Vendors Pro - Gift Wrap by Vendors
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