Change Paypal product item name in Woocommerce












1















My website allows customers to purchase subscriptions plans. It's using Woocommerce to direct clients to paypal for payment.



Once in paypal, the "subscription details" are listed as follows:



Subscription 1524 (Order 1522) - SimplyGram - Premium Plan



How would I go about completely removing "Subscription 1524 (Order 1522) - " from the subscription details?



I have been looking woocommerce hooks in order to solve the issue. There is a pretty useful list of php hooks for woocommerce found here. After sorting through all the hooks, it seems like the closest one to what I want is woocommerce_paypal_get_order_item_name.



My attempt to implement a solution in php is as follows:



add_filter( 'woocommerce_paypal_get_order_item_name', $item_name, $order, $item );
function change_paypal_description( $item_name, $order, $item) {
return 'test';
}


However, this does not seem to do the trick. I assume most likely I am attempting to use the wrong hook? Any help would be incredibly appreciated!










share|improve this question





























    1















    My website allows customers to purchase subscriptions plans. It's using Woocommerce to direct clients to paypal for payment.



    Once in paypal, the "subscription details" are listed as follows:



    Subscription 1524 (Order 1522) - SimplyGram - Premium Plan



    How would I go about completely removing "Subscription 1524 (Order 1522) - " from the subscription details?



    I have been looking woocommerce hooks in order to solve the issue. There is a pretty useful list of php hooks for woocommerce found here. After sorting through all the hooks, it seems like the closest one to what I want is woocommerce_paypal_get_order_item_name.



    My attempt to implement a solution in php is as follows:



    add_filter( 'woocommerce_paypal_get_order_item_name', $item_name, $order, $item );
    function change_paypal_description( $item_name, $order, $item) {
    return 'test';
    }


    However, this does not seem to do the trick. I assume most likely I am attempting to use the wrong hook? Any help would be incredibly appreciated!










    share|improve this question



























      1












      1








      1








      My website allows customers to purchase subscriptions plans. It's using Woocommerce to direct clients to paypal for payment.



      Once in paypal, the "subscription details" are listed as follows:



      Subscription 1524 (Order 1522) - SimplyGram - Premium Plan



      How would I go about completely removing "Subscription 1524 (Order 1522) - " from the subscription details?



      I have been looking woocommerce hooks in order to solve the issue. There is a pretty useful list of php hooks for woocommerce found here. After sorting through all the hooks, it seems like the closest one to what I want is woocommerce_paypal_get_order_item_name.



      My attempt to implement a solution in php is as follows:



      add_filter( 'woocommerce_paypal_get_order_item_name', $item_name, $order, $item );
      function change_paypal_description( $item_name, $order, $item) {
      return 'test';
      }


      However, this does not seem to do the trick. I assume most likely I am attempting to use the wrong hook? Any help would be incredibly appreciated!










      share|improve this question
















      My website allows customers to purchase subscriptions plans. It's using Woocommerce to direct clients to paypal for payment.



      Once in paypal, the "subscription details" are listed as follows:



      Subscription 1524 (Order 1522) - SimplyGram - Premium Plan



      How would I go about completely removing "Subscription 1524 (Order 1522) - " from the subscription details?



      I have been looking woocommerce hooks in order to solve the issue. There is a pretty useful list of php hooks for woocommerce found here. After sorting through all the hooks, it seems like the closest one to what I want is woocommerce_paypal_get_order_item_name.



      My attempt to implement a solution in php is as follows:



      add_filter( 'woocommerce_paypal_get_order_item_name', $item_name, $order, $item );
      function change_paypal_description( $item_name, $order, $item) {
      return 'test';
      }


      However, this does not seem to do the trick. I assume most likely I am attempting to use the wrong hook? Any help would be incredibly appreciated!







      php wordpress woocommerce paypal hook-woocommerce






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 18:38









      LoicTheAztec

      91.1k1365105




      91.1k1365105










      asked Nov 27 '18 at 16:32









      Sam SebreeSam Sebree

      62




      62
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You are not using the correct way for woocommerce_paypal_get_order_item_name, so your code can't work as it is. Try instead the following:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          return 'test';
          }


          Or targeting "subscription" product type:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          // get an instance of the WC_Product object
          $product = $item->get_product();

          // Target subscriptions type
          if( $product->is_type( 'subscription' ) )
          $item_name = 'test';

          return $item_name;
          }


          Code goes in function.php file of your active child theme (or active theme). It should works.





          There is two other filter hooks that you can use specifically for Paypal to alter the details that are sent:





          • woocommerce_paypal_args that has 2 arguments: $args and $order


          • woocommerce_paypal_line_item that has 5 arguments $item, $item_name, $quantity, $amount and $item_number.


          The first one allow to change order details and the second one allow to change order item details before the data is sent to the gateway.



          Related threads for woocommerce_paypal_args on StackOverFlow.






          share|improve this answer


























          • Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

            – Sam Sebree
            Nov 29 '18 at 1:17













          • @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

            – LoicTheAztec
            Nov 29 '18 at 1:25













          • Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

            – Sam Sebree
            Nov 29 '18 at 1:36













          • @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

            – LoicTheAztec
            Nov 29 '18 at 1:38













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53504134%2fchange-paypal-product-item-name-in-woocommerce%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You are not using the correct way for woocommerce_paypal_get_order_item_name, so your code can't work as it is. Try instead the following:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          return 'test';
          }


          Or targeting "subscription" product type:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          // get an instance of the WC_Product object
          $product = $item->get_product();

          // Target subscriptions type
          if( $product->is_type( 'subscription' ) )
          $item_name = 'test';

          return $item_name;
          }


          Code goes in function.php file of your active child theme (or active theme). It should works.





          There is two other filter hooks that you can use specifically for Paypal to alter the details that are sent:





          • woocommerce_paypal_args that has 2 arguments: $args and $order


          • woocommerce_paypal_line_item that has 5 arguments $item, $item_name, $quantity, $amount and $item_number.


          The first one allow to change order details and the second one allow to change order item details before the data is sent to the gateway.



          Related threads for woocommerce_paypal_args on StackOverFlow.






          share|improve this answer


























          • Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

            – Sam Sebree
            Nov 29 '18 at 1:17













          • @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

            – LoicTheAztec
            Nov 29 '18 at 1:25













          • Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

            – Sam Sebree
            Nov 29 '18 at 1:36













          • @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

            – LoicTheAztec
            Nov 29 '18 at 1:38


















          0














          You are not using the correct way for woocommerce_paypal_get_order_item_name, so your code can't work as it is. Try instead the following:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          return 'test';
          }


          Or targeting "subscription" product type:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          // get an instance of the WC_Product object
          $product = $item->get_product();

          // Target subscriptions type
          if( $product->is_type( 'subscription' ) )
          $item_name = 'test';

          return $item_name;
          }


          Code goes in function.php file of your active child theme (or active theme). It should works.





          There is two other filter hooks that you can use specifically for Paypal to alter the details that are sent:





          • woocommerce_paypal_args that has 2 arguments: $args and $order


          • woocommerce_paypal_line_item that has 5 arguments $item, $item_name, $quantity, $amount and $item_number.


          The first one allow to change order details and the second one allow to change order item details before the data is sent to the gateway.



          Related threads for woocommerce_paypal_args on StackOverFlow.






          share|improve this answer


























          • Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

            – Sam Sebree
            Nov 29 '18 at 1:17













          • @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

            – LoicTheAztec
            Nov 29 '18 at 1:25













          • Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

            – Sam Sebree
            Nov 29 '18 at 1:36













          • @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

            – LoicTheAztec
            Nov 29 '18 at 1:38
















          0












          0








          0







          You are not using the correct way for woocommerce_paypal_get_order_item_name, so your code can't work as it is. Try instead the following:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          return 'test';
          }


          Or targeting "subscription" product type:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          // get an instance of the WC_Product object
          $product = $item->get_product();

          // Target subscriptions type
          if( $product->is_type( 'subscription' ) )
          $item_name = 'test';

          return $item_name;
          }


          Code goes in function.php file of your active child theme (or active theme). It should works.





          There is two other filter hooks that you can use specifically for Paypal to alter the details that are sent:





          • woocommerce_paypal_args that has 2 arguments: $args and $order


          • woocommerce_paypal_line_item that has 5 arguments $item, $item_name, $quantity, $amount and $item_number.


          The first one allow to change order details and the second one allow to change order item details before the data is sent to the gateway.



          Related threads for woocommerce_paypal_args on StackOverFlow.






          share|improve this answer















          You are not using the correct way for woocommerce_paypal_get_order_item_name, so your code can't work as it is. Try instead the following:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          return 'test';
          }


          Or targeting "subscription" product type:



          add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
          function change_paypal_item_name( $item_name, $order, $item ) {
          // get an instance of the WC_Product object
          $product = $item->get_product();

          // Target subscriptions type
          if( $product->is_type( 'subscription' ) )
          $item_name = 'test';

          return $item_name;
          }


          Code goes in function.php file of your active child theme (or active theme). It should works.





          There is two other filter hooks that you can use specifically for Paypal to alter the details that are sent:





          • woocommerce_paypal_args that has 2 arguments: $args and $order


          • woocommerce_paypal_line_item that has 5 arguments $item, $item_name, $quantity, $amount and $item_number.


          The first one allow to change order details and the second one allow to change order item details before the data is sent to the gateway.



          Related threads for woocommerce_paypal_args on StackOverFlow.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 27 '18 at 18:36

























          answered Nov 27 '18 at 18:25









          LoicTheAztecLoicTheAztec

          91.1k1365105




          91.1k1365105













          • Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

            – Sam Sebree
            Nov 29 '18 at 1:17













          • @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

            – LoicTheAztec
            Nov 29 '18 at 1:25













          • Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

            – Sam Sebree
            Nov 29 '18 at 1:36













          • @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

            – LoicTheAztec
            Nov 29 '18 at 1:38





















          • Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

            – Sam Sebree
            Nov 29 '18 at 1:17













          • @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

            – LoicTheAztec
            Nov 29 '18 at 1:25













          • Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

            – Sam Sebree
            Nov 29 '18 at 1:36













          • @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

            – LoicTheAztec
            Nov 29 '18 at 1:38



















          Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

          – Sam Sebree
          Nov 29 '18 at 1:17







          Thank you so much for your help! I tried implementing both solutions and unfortunately I haven't seen a change in the paypal checkout. Here is a screenshot of what the checkout currently looks like after adding your code to my theme's functions.php: imgur.com/a/t8hQ43q Is it possible 'change_paypal_item_name' isn't the hook were looking for?

          – Sam Sebree
          Nov 29 '18 at 1:17















          @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

          – LoicTheAztec
          Nov 29 '18 at 1:25







          @SamSebree change_paypal_item_name is not a hook, but the function name that is hooked (that I have named myself). Now it's not normal that it doesn't work, as this is really the right hook to be used and in the rightway. As you can see in the linked source code, it really filters the item name before it's send to paypal. So there is something else that is interacting in your installation... Remember that those hooks are just for the "Normal" paypal included in Woocommerce.

          – LoicTheAztec
          Nov 29 '18 at 1:25















          Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

          – Sam Sebree
          Nov 29 '18 at 1:36







          Ah you're right, I suppose "woocommerce_paypal_get_order_item_name" is the hook in the case. I also have the woocommerce subscriptions plugin installed. Perhaps its possible this is responsible for changing what item name is being sent to paypal? Also just to clarify, I don't necessarily need to change the item name as a whole. My primary objective is to delete the bit that says "Subscription x (Order x)" So perhaps there is a hook that can allow me to change this prefix?

          – Sam Sebree
          Nov 29 '18 at 1:36















          @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

          – LoicTheAztec
          Nov 29 '18 at 1:38







          @SamSebree Maybe yes it's possible. But subscriptions is a very huge and complicate plugin. So things with it get always complicated when trying to do customizations on it.

          – LoicTheAztec
          Nov 29 '18 at 1:38






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53504134%2fchange-paypal-product-item-name-in-woocommerce%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks