Days
Hours
Minutes
Seconds

Super Black Friday Sale!

0
No products in the cart.

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 741 total)
  • Author
    Posts
  • in reply to: PHP Settings to ignore the WordPress error #10655
    blankabctest483
    Member

    Errors should normally be good for telling you something went wrong

    But if you really want, due to some special purposes, to hide Php errors in WP, then

    Open Your wp-config. php File.

    Replace the Debug Lines. Replace the existing lines with the following code snippet:

    ini_set('display_errors','Off'); 
    ini_set('error_reporting', E_ALL ); 
    define('WP_DEBUG', false); 
    define('WP_DEBUG_DISPLAY', false);
    

    Save and Upload.

    Alternatively, if you can access the php.ini file, then use the following line (restart your httpd after changing the ini file):

    display_errors = On
    
    in reply to: PHP DOMDocument ignores first table's closing tag #10657
    blankabctest483
    Member

    Enclose your $html with <body> and </body>

    Revised Code (Note: I commented out the $stream lines)

    <?php
    $html = <<<HTML
    <body>
    <table>
    <tr><td>A</td><td>Rose</td></tr>
    </table>
    
    <h1>Leave me behind</h1>
    
    <table>
    <tr><td>By</td><td>Any</td></tr>
    </table>
    
    <table>
    <tr><td>Other</td><td>Name</td></tr>
    </table>
    </body>
    HTML;
    
    $dom = new \DOMDocument();
    $dom->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
    
    $tables = $dom->getElementsByTagName('table');
    // $stream = \fopen('php://output', 'w+');
    
    for ($i = 0; $i < $tables->length; ++$i) {
        $rows = $tables->item($i)->getElementsByTagName('tr');
    
        for ($j = 0; $j < $rows->length; ++$j) {
            echo trim($rows->item($j)->nodeValue) . "<br><br>";
        }
    }
    
    // fclose($stream);
    ?>
    

    Alternatively, change

    $dom->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
    

    to

    $dom->loadHTML($html, LIBXML_HTML_NODEFDTD);
    
    blankabctest483
    Member

    n your Laravel project, locate the config/database.php file. Inside this file, find the ‘connections’ array and look for the configuration related to your MySQL connection.

    Within the MySQL connection configuration, add or update the ‘collation’ parameter to use a supported collation like ‘utf8mb4_unicode_ci’

    in reply to: WordPress translation file also translate text in css files #9906
    blankabctest483
    Member

    There are a few things you should be aware of …

    Always escape your output, even for attributes

    Use esc_attr__() to return the translated value
    or esc_attr_e() to echo the translated
    value. If you do not need a translation, just
    use esc_attr() / echo esc_attr().

    How to pass variables inside translation functions

    You can’t translate text if you actually don’t know what that text
    is. According to the docs, you must pass a string, you can’t
    translate variables
    .

    Therefore this does not work: _e( 'Current status:' . $status, 'my-text-domain' );

    The solution: use sprintf to insert variables inside strings.

    echo sprintf( __( 'Current status: %s', 'my-text-domain' ), $status );
    

    Avoid double echoing

    So, instead of (see line 3 in your code snippet): echo esc_html( _e( ... ) );
    do something like: esc_html_e( .... );

    Doing the same:
    esc_html_e( 'Blablabla' );
    echo esc_html__( 'Blablabla' );
     

    Read more about the differences here:
    __() – return translated string [docs]
    _e() – echo translated string [docs]
    _n() – return translated singular/plural form of a string based on supplied number [docs]
    _x() – return translated string with gettext context [docs]
    _ex() – echo translated string with gettext context [docs]
    esc_html__() – escape and return translated string for safe use in HTML output [docs]
    esc_html_e() – escape and echo translated string for safe use in HTML output [docs]
    esc_html_x() – escape and return translated string with gettext context for safe use in HTML output [docs]
    esc_attr__() – escape and return translated string for safe use in an attribute [docs]
    esc_attr_e() – escape and echo translated string for safe use in an attribute [docs]
    esc_attr_x() – escape and return translated string with gettext context for safe use in an attribute [docs]

    Finally, your code should look something like this

    <?php  
    
    $domain = 'wp-event-manager-registrations';
    $status = $wp_post_statuses[ get_post_status( $registration_id ) ]->label;  
    
    if ( strtolower( $status ) === 'confirmed' ) {
        $status_i18n = __( 'Confirmed', $domain );
    } else {
        $status_i18n = __( 'Not Confirmed', $domain );
    }  
    
    ?>
    
    <td data-title="<?php esc_attr_e( 'Status', $domain ); ?>">
      <span class="wpem-tbl-status <?php echo esc_attr( $status ); ?>">
      <?php echo sprintf( esc_html__( 'Status: %s', $domain ), $status_i18n ); ?>
      </span>
    </td>  
    
    <!-- Alternatively - if you only want to output the value (without further text) -->  
    
    <td data-title="<?php esc_attr_e( 'Status', $domain ); ?>">
        <span class="wpem-tbl-status <?php echo esc_attr( $status ); ?>">
        <?php echo esc_html( $status_i18n ); ?>
        </span>
    </td>
    

    Also make sure that the value of $status has not already been translated elsewhere in your code.

    in reply to: Display a NEW tag/icon on a 1 week old WordPress post #9908
    blankabctest483
    Member

    Your PHP code looks good for retrieving posts with the category ‘whats-new’ and displaying them with a "NEW" icon for posts less than one week old. However, there are a couple of minor corrections you can make for better structure and readability. Also, the closing tag seems to be unnecessary and might be a typo.

    Here’s an updated version of your code:

    <?php
    $args = array(
        'post_type'      => 'post',
        'post_status'    => 'publish',
        'category_name'  => 'whats-new',
        'posts_per_page' => 10,
    );
    
    $arr_posts = new WP_Query($args);
    
    if ($arr_posts->have_posts()) :
        while ($arr_posts->have_posts()) :
            $arr_posts->the_post();
            ?>
            <article>
                <div class="news">
                    <a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4></a>
                    <?php
                    if (strtotime(get_the_date()) < strtotime('-1 week')) {
                        echo '';
                    } else {
                        echo '<span class="icon icon-new">NEW</span>';
                    }
                    ?>
                </div>
            </article>
            <?php
        endwhile;
        wp_reset_postdata();
    endif;
    ?>
    
    blankabctest483
    Member

    You can go 2 ways here.

    Solution 1 (hooks):
    Show before main content and after the breadcrumbs

    add_action('woocommerce_before_main_content', 'show_category_title', 40, 2);
    
    function show_category_title() {
        $cat_title = single_tag_title("", false);
        echo '<h1>' . $cat_title . '</h1>';
    }
    

    Solution 2 (PHP templates overwrite):

    1. Copy archive-product.php from /wp-content/plugins/woocommerce/templates to /wp-content/YOUR_THEME/woocommerce
    2. Edit with custom code. Example:
    <header class="woocommerce-products-header col-span-12">
    <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
    <?php do_action( 'woocommerce_archive_description' ); ?>
    </header>
    
    in reply to: Ajax wordpress : The data is not transmitted to the template #9915
    blankabctest483
    Member

    Here is your modify template-posts-container.php temaplte code, You should try

    <div id="posts-container">
        <?php foreach ($custom_posts as $post): setup_postdata($post); ?>
            <h2><?php echo esc_html(get_the_title($post)); ?></h2>
            <div class="post-content"><?php echo wp_kses_post(get_the_content(null, false, $post)); ?></div>
        <?php endforeach; wp_reset_postdata(); ?>
    </div>
    

    setup_postdata($post) to set up global post data. This allows you to
    use template tags like get_the_title() and get_the_content().
    get_the_title($post) and get_the_content(null, false, $post) are used
    to fetch the title and content of each post.

    in reply to: Ajax wordpress : The data is not transmitted to the template #9914
    blankabctest483
    Member
    <?php extract($args); ?>
    <div id="posts-container">
        <?php foreach ($custom_posts as $post): ?>
            <?php echo $post->post_title; ?>
        <?php endforeach; ?>
    </div>
    

    In the template. Saved the problem.

    in reply to: Cannot redeclare function error in wordpress #9912
    blankabctest483
    Member

    I dont know how start.php is included, but probably it’s included more than once.

    Quick fix, surrounding your wpb_dynamic_init with

    if (!function_exists('wpb_dynamic_init')) {
        // your function
    }
    

    Better solution, find why start.php is included many times. You can use debug_backtrace in start.php to visualize the calls-stack

    blankabctest483
    Member

    Use the following, to add a custom field in WooCommerce admin shipping, to each shipping methods setting fields:

    add_action('woocommerce_init', 'woocommerce_shipping_instances_form_fields_filters');
    function woocommerce_shipping_instances_form_fields_filters(){
        foreach( WC()->shipping->get_shipping_methods() as $shipping_method ) {
            add_filter('woocommerce_shipping_instance_form_fields_' . $shipping_method->id, 'shipping_methods_additional_custom_field');
        }
    }
    
    function shipping_methods_additional_custom_field( $settings ) {
        $settings['shipping_comment'] = array(
            'title'         => __('Shipping Comment', 'woocommerce'),
            'type'          => 'text', 
            'placeholder'   => __( 'Enter any additional comments for this shipping method.', 'woocommerce' ),
        );
        return $settings;
    } 
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

    enter image description here

    blankabctest483
    Member

    The hook woocommerce_get_price is obsolete and deprecated since WooCommerce 3 and has been replaced with the following hooks:

    • woocommerce_product_get_price (for products)
    • woocommerce_product_variation_get_price (for variations of a variable product).

    There are some other mistakes in your code. Try the following revised code:

    add_filter('woocommerce_product_get_price', 'country_based_cart_item_price', 100, 2);
    add_filter('woocommerce_product_variation_get_price', 'country_based_cart_item_price', 100, 2);
    
    function country_based_cart_item_price( $price, $product ) {    
        // Define below in the array the desired country codes
        $targeted_countries = array('US');
        $billing_country    = WC()->customer->get_billing_country();
    
        // Only on cart and checkout pages 
        if ( ( is_checkout() || is_cart() ) && in_array($billing_country, $targeted_countries) ){
            // Returns changed price
           return $price / 260 * 1.25;
        }
        return $price;
    } 
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

    See: Change product prices via a hook in WooCommerce 3+

    in reply to: Prevent order go to processing status if condition is true #9921
    blankabctest483
    Member

    You can try the following for Cash on delivery (COD) payment method, replacing in the code both 'my_variable' with the correct slug:

    add_filter( 'woocommerce_cod_process_payment_order_status', 'conditionally_change_cod_order_status_to_pending', 10, 2 );
    function conditionally_change_cod_order_status_to_pending( $status, $order ) {
        $global_var = $GLOBALS; 
    
        if ( isset($global_var['my_variable']) && $global_var['my_variable'] ) {
            return 'pending';
        }
        return $status;
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). It should work.

    blankabctest483
    Member

    To generalize your code for all posts of a custom post type try the following:

    function update_all_acf_datetime_fields() {
        $post_type = 'my_post_type'; // Here define your custom post type
        $field_name = 'date_time';  // Replace with your actual ACF field slug
        $today_date = date('Y-m-d');
    
        // Get all posts IDs from a custom post type
        $posts_ids = get_posts( array(
            'post_type'      => $post_type,
            'post_status'    => 'publish',
            'posts_per_page' => -1,
            'fields'         => 'ids'
        ) );
        
        // Loop through the posts IDs
        foreach( $posts_ids as $post_id ) {
            // Get the current value of the ACF datetime field
            $current_datetime = get_field($field_name, $post_id);
    
            // If the field has a value, update only the date part to today
            if ( ! empty($current_datetime) ) {
                $updated_datetime = $today_date . substr($current_datetime, 10); // Preserve the time part
                update_field($field_name, $updated_datetime, $post_id);
            }
        }
    }
    
    // Call the function to update the ACF datetime field
    update_all_acf_datetime_fields();
    

    It should work…

    blankabctest483
    Member

    So this seems to work for a single post ID, how can I generalise out for all posts in a specific custom post type?

        function update_acf_datetime_field() {
        // Assuming you have the post ID and your ACF field name
        $post_id = 120;  // Replace with your actual post ID
        $field_name = 'date_time';  // Replace with your actual ACF field name
    
        // Get the current value of the ACF datetime field
        $current_datetime = get_field($field_name, $post_id);
    
        // If the field has a value, update only the date part to today
        if ($current_datetime) {
            $today_date = date('Y-m-d');
            $updated_datetime = $today_date . substr($current_datetime, 10); // Preserve the time part
            update_field($field_name, $updated_datetime, $post_id);
        }
    }
    
    // Call the function to update the ACF datetime field
    update_acf_datetime_field();
    
    in reply to: Add class to children based on data attribute of parent #9341
    blankabctest483
    Member

    Without Jquery:

    document.querySelectorAll('.difficulty-wrapper').forEach(wrapper => {
      const difficulty = wrapper.dataset.difficulty || 0;
      const items = [...wrapper.querySelectorAll('.difficulty-item')].slice(0, difficulty);
      items.forEach(item => item.classList.add('active'));
    })
    .difficulty-wrapper {
      display: flex;
      gap: 2px;
    }
    
    .difficulty-wrapper:not(:last-child) {
      margin-bottom: 2px;
    }
    
    .difficulty-item {
      width: 48px;
      height: 32px;
      border-radius: 2px;
      background-color: yellow;
      border: solid 1px red;
    }
    
    .difficulty-item.active {
      background-color: blue;
    }
    <div class="difficulty-wrapper" data-difficulty="1">
      <span class="difficulty-item"></span>
      <span class="difficulty-item"></span>
      <span class="difficulty-item"></span>
      <span class="difficulty-item"></span>
    </div> 
    <div class="difficulty-wrapper" data-difficulty="4">
      <span class="difficulty-item"></span>
      <span class="difficulty-item"></span>
      <span class="difficulty-item"></span>
      <span class="difficulty-item"></span>
    </div> 
Viewing 15 posts - 1 through 15 (of 741 total)