How to change the button text "View Lesson" in LearnDash - learndash

I was trying to change the text through translation but it didn't work. so
the following worked..
add_filter( 'gettext_lds_skins',function( $button_text = '', $post_id =0 ){
$button_text = "Check ";
return $button_text;
}, 10, 2 );
Now why this is hidden as a hook, filter from documentation I don't know

By using the following we manage to change the text of buttons for Lessons and Topics in LearnDash frontend
Nevertheless is causes LearnDash Settings in WordPress customization to display Check,Check Check..So its a partial solution
add_filter( 'gettext_lds_skins',function( $button_text = '', $post_id =0 ){
$button_text = "Check ";
return $button_text;
}, 10, 2 );

Related

Is there a filter or hook t change the WC_Tax::get_rate_label( $key ) in woocommerce?

I am trying to change the Tax label on the cart, checkout order-review and email.
I have tried to create a function with 'woocommerce_get_order_item_totals' and also with 'woocommerce_get_formatted_order_total' No luck. It either remove all or adds a new line but changing the $tax_totals[ $code ]->label
I have a checkbox which gives customers to possibility to apply Tax-exempt for the order. This is all working very good.
If selected it will set TAX Amount to 0.00 but the label keeps on VAT or TAX or BTW (Dutch label)
I added zero-rates in the backend,
Phrase matches used to identify VAT (VAT, V.A.T, IVA, I.V.A., Value Added Tax, TVA, T.V.A., BTW, B.T.W., Tax Exempt, vrijgesteld van BTW)
I added zero-rate by country code
GB Tax Exempt (0%)
NL vrijgesteld van BTW (0%)
And still it shows on the cart, checkout, order-review and email as VAT or(BTW) whatever the country is.
This is what I want to change
I have been looking already for days to find a working solution with no luck.
But I found a solution just now, not sure if it is a hack or good coding but it works for me.
I have this code inside my function.
add_action( woocommerce_checkout_update_order_review','taxexempt_checkout_based_on_checkbox');
function taxexempt_checkout_based_on_checkbox( $post_data) {
global $woocommerce;
$woocommerce->customer->set_is_vat_exempt( false );
parse_str($post_data);
if ( $billing_taxexempt === '1' && $billing_confirmed === '1' &&
!empty($billing_signature) && ! empty($billing_declaration)){
$woocommerce->customer->set_is_vat_exempt( true );
}
}
This will apply the tax-exempt to the order.
I added a filter to this just below ....set_is_vat_exempt( true )..
add_filter( 'woocommerce_countries_tax_or_vat', function () { return __( 'Tax Exempt', 'woocommerce' ); });
And I added a function I found //Change "Billing Details" text to "Shipping Details" on Woocommerce checkout page
I changed it a little bit but it works for me.
function wc_change_field_strings( $translated_text, $text, $domain ) {
$language = get_locale();
$domain = 'woocommerce';
if($language == 'en_GB' ){
switch ( $translated_text ) {
case 'Tax Exempt' :
$translated_text = __( 'Tax Exempt', $domain );
break;
}
return $translated_text;
}
if($language == 'nl_NL' ){
switch ( $translated_text ) {
case 'Tax Exempt' :
$translated_text = __( 'vrijgesteld van BTW', $domain);
break;
}
return $translated_text;
}
}
add_filter( 'gettext', 'wc_change_field_strings', 20, 3 );
Have to add the default case, will do later but it works for, this solution.
Maybe it will work for somebody else or if you have a better solution, let me know.
And the result looks like this.

Gravity Forms Multi Page Losing POST value

I have a complex Gravity Form built, it has 10 pages. I am using fields to build a "string" that I then match to a CPT name to get meta data from to display a selection, based on user choices in the form.
One field I have is not holding its value in POST. I can see it when I select the value on the page, then when I click to next page the value is still there. However, after two pages the value ( and field ) disappear from POST.
This is the function I have put together that builds my product string.
add_filter( 'gform_pre_render_12', 'display_choice_result' );
function display_choice_result( $form ) {
$current_page = GFFormDisplay::get_current_page( $form['id'] );
$html_content = "";
$prod_string = "";
if ( $current_page >= 10 ) {
foreach ( $form['fields'] as &$field ) {
// Check for a class of "product-builder-item" on the field
// I use this as another way to denote what fields to add to string
if ( strpos( $field->cssClass, 'product-builder-item' ) === false ) {
continue;
}
//gather form data to save into html field (Field ID 14 on Form ID 12)
//exclude page break and any hidden fields
if ( $field->id != 14 && $field->type != 'page' ) {
$is_hidden = RGFormsModel::is_field_hidden( $form, $field, array() );
$populated = rgpost( 'input_' . $field->id );
// Make sure the field we are getting the value from is not hidden and has a value
if ( !$is_hidden && $populated !='' ) {
$html_content .= '<li>' . $field->label . ': ' . rgpost( 'input_' . $field->id ) . '</li>';
$prod_string .= rgpost( 'input_' . $field->id );
}
}
}
// Do a bunch of stuff here with the $prod_string variable
// ...
// ...
// ...
}
return $form;
}
Screenshots showing the POST disappearing..The POST field in question is input_22 with a value of 18000
This is one page after I choose from the field
This is two pages after,
Anyone run into this before or have any idea why it would be disappearing?
Thank you.
I was having the same exact issue as you described. I realized that a jQuery function was interfering with Gravity Form process. The jQuery function was set to change a zip code field from type text to tel so the number pad would open up on mobile devices. This is what was causing my issue.

Woocommerce - Change order received text after redirecting from PayPal with IPN

I like to change the thank you page text in case the customer already paid via paypal.
Redirecting via PayPal works fine. Order status is "processing", ok.
But how can I change the thank you text on the redirecting page (https://www.example.com/checkout/order-received/)
I tried the following, with no success:
function my_update_order_status() {
$order = new WC_Order($order_id);
if ($order_status == 'processing')
echo 'NEW MESSAGE';
else
echo 'NOT PAID TEXT';
}
add_filter('woocommerce_thankyou_order_received_text', 'my_update_order_status', 10, 2);
There is an explanation on how to change the thank you page here:
https://wordpress.org/support/topic/how-to-edit-the-thank-youorder-received-page
If you don't wish to do any template modifying then you can include the order received function to adjust it. For example:
function isa_order_received_text( $text, $order ) {
$new = $text . ' All received and an email is on its way to you!.';
return $new;
}
add_filter('woocommerce_thankyou_order_received_text', 'isa_order_received_text', 10, 2 );
The above with add text to the current text output.

How to remove a text field on a CGI perl webpage?

I am rewriting this question to make it specific:
The requirement of the webpage is
Read the rules from a file and populate the text-boxes when the webpage is loaded
An add button to add additional textboxes
A save button to save the rules ( including the additionally added ones back to the file)
A delete button to delete the textboxes which are checked so that the rules in them are not stored back to the file.
My approach :
Use "read_rules" submodule to read the rules from the webpage and if its non empty then use "rule" submodule to print them on webpage. Here each line in the file is read and split with spaces and put in a array of hash and prints on the webpage ("rules" module).
When the sumit button is pressed sumodule "save_rules" is called which saves the rules. The reverse way as in read_rules.
An add button will add additional text areas.
A delete button should delete the text areas which are checked and reload the page so when the page is reloaded the text areas which were checked wont appear and hence when save button is pressed they are not saved in file ??? (this I have to implement)
The code blocks of each submodule I have mentioned are below.
This submodule to print the text boxes and checkbox:
sub rule {
my($num,$rule) = #_;
return join "\n",
"<tr><td><br>",
hidden(
-name => "idx$num",
-default => $rule->{idx},
),
checkbox(
-name => "checkbox$num",
-label => "",
-value => "on",
),
"<td>",
textfield(
-name => "repository$num",
-size => 30,
-default => $rule->{'repo'},
),
"<td>",
textfield(
-name => "branch$num",
-size => 30,
-default => $rule->{'branch'},
),
"<td>",
textfield(
-name => "file$num",
-size => 30,
-default => $rule->{'file'},
),
}
This sumodule to read the rules from file
sub read_rules {
my $rule;
#rules = ..# read the rules from a file, each line is read as an element of an array
for $rule (#rules){
my $rec = {};
($re,$br,$fi) = split (' ', $rule);
$rec->{'repo'} = $re;
$rec->{'branch'} = $br;
$rec->{'file'} = $fi;
push #config, $rec;
}
}
The sumodule to save the rule on webpage ( in text area) back to the file
sub save_rules {
for ($i = 1; param("repository$i"); $i++) {
$repo1 = param("repository$i");
$branch1 = param("branch$i");
$file1 = param("file$i");
my $record = {};
# save back $myrec->{'repo1'} $myrec->{'branch1'} $myrec->{'file1'} to file
}
}
Main function
print start_form();
read_rules();
Delete_all();
my $i = 0;
if (#config) {
foreach $conf (#config) {
$i++;
print rule($i,$conf);
}
print $table_header_string;
if (param("action") eq "Add") {
print(br,rule(++$i),hr);
}
print p( submit (-name => "action" , -value => "Add"));
print p( submit (-name => "action" , -value => "Save"));
print p( submit (-name => "action" , -value => "Delete"));
print end_form();
exit 0;
Delete_rule submodule below has to be coded !!
sub delete_rule(){
#................
}
I would appreciate if some one tells me how to use javascript in cgi so I don't have to load webpage every time a button is pressed.
Edited to address more specific question
Given that you don't want to reload the page each time the button is clicked, you are going to want to use JavaScript to do this. I'll explain how here, and you can click here to see a working jsfiddle example.
<!doctype html>
<html>
<head>
<title>Remove Element On Button Click</title>
</head>
<body>
<input type="text" id="myTextBox" value="something here">
<input type="button" id="btnDelete">
</body>
<script>
document.getElementById('btnDelete').onclick = function ()
{
var textbox = document.getElementById('myTextBox');
textbox.parentNode.removeChild(textbox);
}
</script>
</html>
Notice that I changed the type of input element from submit to button. This automatically prevents the page from reloading.
If you absolutely must use a submit input element (and the jsFiddle example does), you can prevent form submission by changing the Javascript thusly:
document.getElementById('btnDelete').onclick = function (evt)
{
if (!evt) var evt = window.event;
if (evt.preventDefault) { evt.preventDefault(); } else { evt.returnValue = false; }
var textbox = document.getElementById('myTextBox');
textbox.parentNode.removeChild(textbox);
}
The JavaScript can be placed in an external file, if prefered. It's placed at the end of the HTML here so as to ensure that the DOM had fully loaded (and hence the button was available in the DOM) prior to attempting to attach an event handler.
It was unclear to me whether there would be one or multiple 'Delete' buttons in your output, or if there would be one or multiple fields that would need to be removed, but this should point you in the right direction.
This is a pure JavaScript solution. As #vol7ron correctly pointed out, there are JavaScript frameworks, like jQuery, that could be used to do this as well, and if you are already using such a framework it would be advantageous to utilize it, however no such framework is in anyway required to accomplish this.

Contact Form 7 - Mass Checkboxes displayed by line break separation within notification emails

I have a question about the checkbox value items that I receive in my mail after someone fills in my contact form 7.
If someone has checked these three boxes in the form:
CHECKBOX1
CHECKBOX2
CHECKBOX3
Then in my mail they appear as:
CHECKBOX1, CHECKBOX2, CHECKBOX3
However, I would like to change the comma separation into line breaks.
Plus add a unique value for each checkbox so I can add in a URL:
Should be displayed in the email like this:
CHECKBOX1 – URL LINK
CHECKBOX2 – URL LINK
CHECKBOX3 – URL LINK
I really need this, can somebody please tell me where I can change this within contact form 7’s code?
Or does someone know another way without using contact form 7?
For HTML emails,
Edit: wp-content/plugins/contact-form-7/includes/classes.php
Look for function mail_callback. In my version it's at line 631.
Edit the function to be as so:
function mail_callback( $matches, $html = false ) {
if ( isset( $this->posted_data[$matches[1]] ) ) {
$submitted = $this->posted_data[$matches[1]];
if ( $html ) {
$replaced = strip_tags( $replaced );
$replaced = wptexturize( $replaced );
}
if ( is_array( $submitted ) )
$replaced = join( '<br/>', $submitted );
else
$replaced = $submitted;
$replaced = apply_filters( 'wpcf7_mail_tag_replaced', $replaced, $submitted );
return stripslashes( $replaced );
}
if ( $special = apply_filters( 'wpcf7_special_mail_tags', '', $matches[1] ) )
return $special;
return $matches[0];
}