logo
down
shadow

Wordpress Woocommerce Advice with PHP code


Wordpress Woocommerce Advice with PHP code

By : Bruce A
Date : November 22 2020, 10:33 AM
this one helps. I'm working with the woo commerece plugin and i'd like to have a sub heading under the title of each product. Style and format is sorted however i want a particular Category to show in the sub heading section. I've managed to get as far as showing all categories but i want to narrow this down to just one category that is under a parent category. Below is the code i am using, could anyone suggest how i could achieve showing any child category selected under a parent category. , Try this :
code :
<?php 

    global $post, $product;

    $term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all")); //get array containing category details

    $cat_id = ($term_list[0]->parent); //get parent category ID from the above generated array

    $cat_url = get_term_link ($cat_id, 'product_cat'); //get link of parent ID

    $term = get_term( $cat_id, 'product_cat' ); //Get Name of the parent from the parent ID

    $name = $term->name; //Store it into an varialbe

    echo "Artist: <a href='".esc_url($cat_url)."'>".$name."</a>";

?>
    <?php 

        global $post, $product;

        $term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all")); //get array containing category details

        $cat_id = ($term_list[0]->parent); //get parent category ID from the above generated array

       $termchildren = get_term_children( '90' , 'product_cat' ); //New Line in Updattion -1

        $new_cat_id = $termchildren[2];

        $cat_url = get_term_link ($new_cat_id, 'product_cat'); //get link of parent ID

        $term = get_term( $new_cat_id, 'product_cat' ); //Get Name of the parent from the parent ID

        $name = $term->name; //Store it into an varialbe

        echo "Artist: <a href='".esc_url($cat_url)."'>".$name."</a>";

    ?>
    <?php 

        global $post, $product;

        $cat_array = array();
        $term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all")); //get array containing category details

        foreach($term_list as $cat_list)
        {

            array_push($cat_array, $cat_list->term_id);

        }

        $cat_id = ($term_list[0]->parent); //get parent category ID from the above generated array

       $termchildren = get_term_children( '90' , 'product_cat' ); //New Line in Updattion -1

       $final_result = array_intersect($cat_array,$termchildren);

       $final_cat_result = array_values($final_result);

        $new_cat_id = $final_cat_result[0];

        $cat_url = get_term_link ($new_cat_id, 'product_cat'); //get link of parent ID

        $term = get_term( $new_cat_id, 'product_cat' ); //Get Name of the parent from the parent ID

        $name = $term->name; //Store it into an varialbe

        echo "Artist: <a href='".esc_url($cat_url)."'>".$name."</a>";
    ?>


Share : facebook icon twitter icon
eager php newb requesting advice on wordpress code

eager php newb requesting advice on wordpress code


By : Elias Bekele
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Have you tried running the following code. This would only create a div if the post did have comments, meaning you wouldn't need any JavaScript to hide ones without, as they wouldn't exist:
code :
<?php 

if ( get_comments_number() > 0 ) {

echo '<div class="commentbox">';

comments_number( 'no comments', 'one comment', '% comments' );

echo '</div>';

}

?>
Updating tracking code $order_total wordpress woocommerce

Updating tracking code $order_total wordpress woocommerce


By : adarsh selenium
Date : March 29 2020, 07:55 AM
like below fixes the issue I'm trying to get this order tracking to work everything is working apart from the $order_total , This was resolved by changing
code :
 $order_total_without_discount = number_format($order->get_subtotal(), 2, ".", "");
 $order_total_without_discount = number_format($order->get_total(), 2, ".", "");
Wordpress / Woocommerce add comment from code

Wordpress / Woocommerce add comment from code


By : user7386843
Date : March 29 2020, 07:55 AM
Hope that helps i am trying to write product comments manually from the database. , You can try this
code :
<?php

$time = current_time('mysql');

$data = array(
   'comment_post_ID' => 1,
   'comment_author' => 'admin',
   'comment_author_email' => 'admin@admin.com',
   'comment_author_url' => 'http://',
   'comment_content' => 'content here',
   'comment_type' => '',
   'comment_parent' => 0,
   'user_id' => 1,
   'comment_author_IP' => '127.0.0.1',
   'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
   'comment_date' => $time,
   'comment_approved' => 1,
);

wp_insert_comment($data);

?>
Better and shorter solution of PHP code (wordpress, woocommerce)

Better and shorter solution of PHP code (wordpress, woocommerce)


By : user1599265
Date : March 29 2020, 07:55 AM
hop of those help? Well done for a first attempt! However, you're right - you can be doing things better!
Firstly, you don't need the 3 $*_link variables as WooCommerce has 2 conditionals - is_shop() and is_cart() to check if you're on a shop page or a cart page. Also, the , $shop_link & , $cart_link in the setcookies aren't required, so you can safely get rid of them.
code :
function sp_custom_notice() {
}

add_filter( 'woocommerce_init', 'sp_custom_notice' );
Remove code html to wordpress/woocommerce

Remove code html to wordpress/woocommerce


By : Aaron
Date : March 29 2020, 07:55 AM
I hope this helps you . Add these hooksremove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 20);
Related Posts Related Posts :
  • how to run wordpress php snippet mysql update command from ssh and/ultimately cron
  • how to get xml tag by name
  • ModSecurity maximum post limits (PCRE limit errors)
  • Call controller/action in event listener
  • How to improve performance of contacting WebService?
  • PHP nest variable in echoed string that contains a HTML tag in the end
  • Multiple Ajax request for PHP framework
  • Debug Info from Moodle Plugin
  • passing variables through page
  • Passing PHP $result data to Javascript
  • cakePHP File Download was not found or not readable
  • batch waiting until script finishes
  • PHP variables and anchors in URL
  • php eTag generation using php
  • How to check whether the array is an Integer or Not?
  • Is it possible to install Doctrine without PEAR or Composer? If so, how?
  • Call view script of (parent) Abstract controller Zend
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org