Skip to content

Instantly share code, notes, and snippets.

@fervous
Last active January 31, 2018 16:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fervous/cf9cfd26ad24a6b6fc72528df64f2161 to your computer and use it in GitHub Desktop.
Save fervous/cf9cfd26ad24a6b6fc72528df64f2161 to your computer and use it in GitHub Desktop.
add woocommerce gift wrap integration wc vendors pro
Gives vendors an option to allow gift wrapping. Requires https://wordpress.org/plugins/woocommerce-product-gift-wrap/
/* This code should be pasted in your child theme's funcitons.php file */
/* WC Vendors Pro - Gift Wrap Option */
add_action( 'wcv_after_product_details', 'wcv_custom_product_gift_wrapper_enable',10,2 );
function wcv_custom_product_gift_wrapper_enable () {
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'
)
);
}
add_action( 'wcv_after_product_details', 'wcv_custom_product_gift_wrap_price',20,2 );
function wcv_custom_product_gift_wrap_price () {
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' ),
)
);
}
/* WC Vendors Pro - Gift Wrap Option - save data */
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment