Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Free products
- This topic has 16 replies, 2 voices, and was last updated 3 years ago by era_uma_vez.
-
AuthorPosts
-
September 11, 2020 at 1:47 pm #16345era_uma_vezParticipant
Hello again,
I got that subdir from your documentation: https://www.soft79.nl/documentation/wjecf/usage/
Could you please reply to my second question, because i already tried both php codes and don’t work – i am still with selection boxes<?php
/**
* Single coupon ( for the “Select Free Product” on Cart or Checkout page )
*
* This template can be overridden by copying it to yourtheme/woocommerce-auto-added-coupons/coupon-select-free-product.php
*
* @version 2.5.1
*/defined(‘ABSPATH’) or die();
$tooltip = sprintf(
_n(
‘You can select one free product.’, //singular
‘You can select up to %d free products.’, //plural
$max_quantity,
‘woocommerce-jos-autocoupon’
),
$max_quantity
);$input_type = $allow_multiple_products ? ‘number’ : ‘radio’;
//This DOM object will manage the total quantity of the selected products
$totalizer_id = $id_prefix . ‘_total_qty’;?>
<div class=”wjecf-select-free-products coupon-<?php echo esc_attr( sanitize_title( $coupon_code ) ); ?>”>
<h3><?php echo WJECF_API()->get_select_free_product_message( $coupon ); ?></h3>
<input type=”hidden” name=”<?php echo $name_prefix; ?>[coupon]” value=”<?php echo esc_attr( $coupon_code ); ?>” />
<input type=”hidden” id=”<?php echo $totalizer_id; ?>” data-wjecf-qty-max=”<?php echo $max_quantity; ?>” />
<ul class=”wjecf-cols cols-4″>
<?php
$product_rendered = false;
$product_selected = false;foreach ( $form_items as $key => $form_item ):
$product = $form_item->getProduct();
if ( ! $product instanceof WC_Product || ! $product->is_in_stock() ) {
//Only display items that are in stock
continue;
}$value = $form_item->getQuantity();
$product_id = $form_item->getProductId();
$field_id = esc_attr( $id_prefix . ‘_’ . $key ); // e.g. wjecf_sel_0_0
$field_name_prefix = esc_attr( “{$name_prefix}[products][{$key}]” ); // e.g. wjecf_sel[0][product][0]$product_rendered = true;
$product_selected = $product_selected || ! empty( $value );
?>- <input type=”hidden” name=”<?php echo $field_name_prefix; ?>[product_id]” value=”<?php echo $product_id; ?>” />
<?php
switch( $input_type ) {
case ‘radio’:
echo ‘<input type=”radio” id=”‘ . $field_id . ‘” name=”‘ . $name_prefix . ‘[selected_product]” value=”‘ . $product_id . ‘” ‘ . ( empty( $value ) ? ” : ‘ checked=”checked”‘ ) . ‘ />’;
break;
case ‘checkbox’:
echo ‘<input type=”checkbox” id=”‘ . $field_id . ‘” name=”‘ . $field_name_prefix . ‘[quantity]” value=”1″ ‘ . ( empty( $value ) ? ” : ‘ checked=”checked”‘ ) . ‘ title=”‘ . esc_attr( $tooltip ) . ‘” data-wjecf-qty-totalizer=”‘ . $id_prefix . ‘_total_qty” />’;
break;
case ‘number’:
echo ‘<input type=”number” id=”‘ . $field_id . ‘” name=”‘ . $field_name_prefix . ‘[quantity]” value=”‘ . intval( $value ) . ‘” min=”0″ max=”‘ . $max_quantity . ‘” title=”‘ . esc_attr( $tooltip ) . ‘” data-wjecf-qty-totalizer=”‘ . $id_prefix . ‘_total_qty” />’;
break;
}
echo ‘<label for=”‘ . $field_id . ‘”>’ . esc_html( $product->get_title(), ‘woocommerce’ ) . ‘</label><br>’;
echo $product->get_image();//Variable product attributes
if ( $product->is_type( ‘variable’ ) ) {
$template->render_attribute_selectors( $product, $form_item->getAttributes(), $field_id, $field_name_prefix . ‘[attributes]’ );
}
?><?php
endforeach;
if ( $product_rendered && $input_type == ‘radio’ ) {
echo ‘- ‘;
echo ‘<input type=”radio” id=”‘ .$id_prefix . ‘_none” name=”‘ . $name_prefix . ‘[selected_product]”‘ . ( $product_selected ? ” : ‘checked=”checked”‘ ) . ‘ />’;
echo ‘<label for=”‘ .$id_prefix . ‘_none” />’ . __( “No product” ) . ‘</label>’;
echo ‘‘;
}
?><p>
</div>This was the last code:
<?php
/**
* Select Free Product on Cart page
*
* This template can be overridden by copying it to yourtheme/woocommerce-auto-added-coupons/cart/select-free-product.php
*
* @version 2.6.0
*/defined( ‘ABSPATH’ ) or die();
/**************************************************************************
Available variables:
$free_gift_coupons : (deprecated) An array of WC_Coupon objects applied to the cart that grant free product selections
$template : The template helper object (WJECF_Pro_Free_Products_Template)
$coupons_form_data : An array with the following info:
[
$coupon_code =>
[
‘coupon’ => The WC_Coupon object
‘coupon_code’ => The coupon code
‘allow_multiple_products’ => True if multiplication is enabled for this coupon
‘form_items’ => WJECF_Free_Product_Item objects. Contains all info about the free products
‘selected_quantity’ => Amount of items selected by the customer
‘max_quantity’ => The max amount of free products for this coupon
‘name_prefix’ => The name prefix for all form input elements (checkbox / radiobutton / input type=”number”) for this coupon (e.g. ‘wjecf_free_sel[0]’)
‘id_prefix’ => The unique prefix to use for all DOM elements for this coupon ( e.g. ‘wjecf_free_sel_0’)
‘totalizer_id’ => The id of the <input> that is used to count the total amount of selected items (e.g. ‘wjecf_free_sel_0_total_qty’)
‘template’ => The template helper object (WJECF_Pro_Free_Products_Template)
],
]**************************************************************************/
//Don’t display if no free product selections…
if ( empty( $coupons_form_data ) ) {
return;
}?>
<tr class=”wjecf-fragment-cart-select-free-product wjecf-auto-submit”>
<td colspan=”6″ data-title=”<?php _e( ‘Free products’, ‘woocommerce-jos-autocoupon’ ); ?>”>
<?phpforeach ( $coupons_form_data as $coupon_code => $coupon_form_data ) :
$template->render_template( ‘coupon-select-free-product.php’, $coupon_form_data );
endforeach;?>
</td>
</tr>September 11, 2020 at 4:28 pm #16346Soft79KeymasterWhat is the exact path + filename of the override file?
September 13, 2020 at 8:50 pm #16349Soft79KeymasterWhat is the full path and filename of the override file?
September 13, 2020 at 9:30 pm #16352Soft79KeymasterWhere exactly did you place the php file?
September 13, 2020 at 10:01 pm #16354era_uma_vezParticipantPlease delete the last post.
ThanksSeptember 14, 2020 at 7:03 am #16357Soft79KeymasterPath must be yourtheme/woocommerce-auto-added-coupons/coupon-select-free-product.php as mentioned in the template.
Please note that 2.5.1 is an old template version, so possibly it requires some changes.
Stop posting sensitive information on this public forum, you can email to admin at soft79.nl
September 14, 2020 at 8:21 am #16358era_uma_vezParticipantDear ….
1. I am already using my theme on the url
2. I gave you access to it (as administrator) did you check it?
3. Could you update this “Please note that 2.5.1 is an old template version, so possibly it requires some changes.”I need your support, could you help me?
I am with this problem since day 10 and no further info about this problem, read the forum, post
and tried my best (using the info available)Regards,
EraSeptember 14, 2020 at 1:40 pm #16362Soft79KeymasterYou named the file wp-content/themes/woodmart-child/woocommerce-auto-added-coupons/cart/select-free-product.php
It must be wp-content/themes/woodmart-child/woocommerce-auto-added-coupons/coupon-select-free-product.php
as mentioned in the template file.Rename the file first.
September 14, 2020 at 4:31 pm #16364Soft79KeymasterWhat do you want to accomplish?
I logged in into your backend and see two overrides (cart/select-free-product.php and checkout/select-free-product.php) both files are not the snippet you mentioned in your first post.
September 14, 2020 at 4:33 pm #16365era_uma_vezParticipantI don’t no anything about code, I just read that code on your forum and tried to use it. Because before wasn’t working.
I will try your solution, just now.Regards,
September 14, 2020 at 4:41 pm #16367Soft79KeymasterDon’t just paste a piece of code if you don’t know what it does. What is the problem you want to solve?
September 14, 2020 at 6:18 pm #16368era_uma_vezParticipantHello again,
Thank you for your reply.
What I am trying to solve?
I would like to show the free products without selection box, like you have on your documentation!> I missed one file, that was the first reason (so nothing was showing up) :/
> The second reason is the plugin doesn’t support webp images; please test yourself.Questions
1. How to align to left the text and radio (like on your documentation): https://ibb.co/QkJWJPT
2. How to configure the free products, could you help me?
I would like to use “Allow multiplication of the free products” but just for my main products (where I can define which categories are going to be used for SUM”
I tried to “Exclude accessories but didn’t work” How and where I exclude or define the SUM categories.Thanks for your support
EraSeptember 14, 2020 at 7:29 pm #16370Soft79KeymasterYou don’t need the template override.
Image is not displayed because something (a plugin or your theme) sets the width and height to 1. Try disabling plugins one by one to find out which one causes this.
1. Apply this custom css:
.shop_table tr.wjecf-fragment-cart-select-free-product td:last-child { text-align: left; }
2. Set minimum quantity of matching products to: 1 and on the ‘usage restrictions’ tab choose the products or categories that must be taken into account.
September 14, 2020 at 7:45 pm #16371Soft79KeymasterAdditionally, about the missing thumbnails:
I installed the ‘regenerate thumbnails’-plugin and tried to regenerate the thumbnail of 1blackpen.webp. It shows the message ‘ERROR: The current image editor cannot process this file type’ so it’s probably not related to any plugin. I’m not even sure if webp is supported by WordPress. I suggest you contact WordPress support about this issue.
September 14, 2020 at 8:05 pm #16372era_uma_vezParticipantHello again.
“Set minimum quantity of matching products to: 1 and on the ‘usage restrictions’ tab choose the products or categories that must be taken into account.”
Works! ThanksThere is a way (via CSS) to reorder the select box? Please check this: https://ibb.co/LdVNHbB
Could be after the title of after the image.
If there isn’t I am OK too.WEBP
Yes, wordpress support it. I am using WEBP on 90% of my images (you can check by yourself)
I used “WP Add Mime Types” to upload because I don’t know how to allow via .htaccess but woocommerce support it.CSS
The CSS worked fine, thanks!Thanks for your support
- <input type=”hidden” name=”<?php echo $field_name_prefix; ?>[product_id]” value=”<?php echo $product_id; ?>” />
-
AuthorPosts
- You must be logged in to reply to this topic.