woocommerce-codes
<?php // This you will find in includes/class-wc-form-handler.php ?>
<div>
<a href="<?php esc_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ); ?>"> Register</a>
</div>
// This function adds a addthis social share button in single product page
add_action('woocommerce_share','wooshare');
function wooshare(){?>
<?php global $xng_add_this_pub; ?>
<?php if(!empty ( $xng_add_this_pub )) : ?>
<div class="product-share">
<?php _e('<h2>Share this Product</h2>','woo'); ?>
<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $xng_add_this_pub; ?>" async="async"></script>
<ul class="post-sharing addthis_toolbox">
<a class="addthis_button_facebook"><i class="fa fa-facebook"></i></a>
<a class="addthis_button_twitter"><i class="fa fa-twitter"></i></a>
<a class="addthis_button_email"><i class="fa fa-envelope"></i></a>
<a class="addthis_button_more"><i class="fa fa-plus"></i></a>
</ul>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php }
// [Ref:][http://www.remicorson.com/mastering-woocommerce-products-custom-fields/]
/*===================================================================
== FUNCTIONS FOR FREE PRODUCT & TOTAL PRODUCT
====================================================================*/
/****************CUSTOM FIELD FOR CUSTOM GENERAL FIELD**************************************************/
// Add Free Number Custom Field in Woocommerce
//Display Field
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
woocommerce_wp_text_input(
array(
'id' => 'free_offer',
'label' => __( '<strong style="color:#239804">Your Free Products</strong>', 'woocommerce' ),
'placeholder' => '',
'description' => __( 'Please enter a number', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
woocommerce_wp_text_input(
array(
'id' => 'offer_text_field',
'label' => __( '<strong>Your Offer</strong>', 'woocommerce' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Enter Your 1st Offer Info.', 'woocommerce' )
)
);
woocommerce_wp_text_input(
array(
'id' => 'next_text_field',
'label' => __( '<strong>Your Other Offers</strong>', 'woocommerce' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Enter Your 2nd Offer Info.', 'woocommerce' )
)
);
echo '</div>';
}//woo_add_custom_general_fields
function woo_add_custom_general_fields_save( $post_id ){
//Number Field
$woocommerce_number_field = $_POST['free_offer'];
if( !empty( $woocommerce_number_field ) )
update_post_meta( $post_id, 'free_offer', esc_attr( $woocommerce_number_field ) );
// Text Field
$woocommerce_text_field = $_POST['offer_text_field'];
update_post_meta( $post_id, 'offer_text_field', esc_attr( $woocommerce_text_field ) );
// Text Field
$woocommerce_text_field = $_POST['next_text_field'];
update_post_meta( $post_id, 'next_text_field', esc_attr( $woocommerce_text_field ) );
}//woo_add_custom_general_fields_save( $post_id )
/*================================================================
Function for front-end in cart.php for free products
=================================================================*/
function free_products(){
global $woocommerce ,$product, $post;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$my_var = $cart_item['product_id'];
$free_number = get_post_meta( $my_var, 'free_offer', true );
$free_product = $cart_item['quantity'] * $free_number;
echo apply_filters( 'woocommerce_cart_item_quantity', $free_product, $cart_item_key );
}
}
/*================================================================
Function for front-end in cart.php for Total products
=================================================================*/
function total_products(){
global $woocommerce;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$my_var = $cart_item['product_id'];
$free_number = get_post_meta( $my_var, 'free_offer', true );
$item_quantity = $cart_item['quantity'];
$free_product = $item_quantity * $free_number;
$total_product = $item_quantity + $free_product;
echo apply_filters( 'woocommerce_cart_item_quantity', $total_product, $cart_item_key );
}
}